0

I'm trying to add style to TextInputLayout but when I select any kind of style to add, my app crashes - without any style it does not.

<com.google.android.material.textfield.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        app:passwordToggleEnabled="true"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        >

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:hint="Password"
            android:inputType="textPassword"> 

        </com.google.android.material.textfield.TextInputEditText>

</com.google.android.material.textfield.TextInputLayout>

Also it's same with any material (buttons etc.) I can not use style.

My implementation :

implementation 'com.google.android.material:material:1.0.0'

StackTrace Error :

    E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.halitkalayci.veterinerapp, PID: 4476
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.halitkalayci.veterinerapp/com.halitkalayci.veterinerapp.LoginActivity}: android.view.InflateException: Binary XML file line #37: Binary XML file line #37: Error inflating class <unknown>
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: android.view.InflateException: Binary XML file line #37: Binary XML file line #37: Error inflating class <unknown>
     Caused by: android.view.InflateException: Binary XML file line #37: Error inflating class <unknown>
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at android.view.LayoutInflater.createView(LayoutInflater.java:647)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at com.halitkalayci.veterinerapp.LoginActivity.onCreate(LoginActivity.java:18)
        at android.app.Activity.performCreate(Activity.java:7136)
        at android.app.Activity.performCreate(Activity.java:7127)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
        at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:248)
        at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:222)
E/AndroidRuntime:     at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:150)
        at com.google.android.material.internal.ThemeEnforcement.obtainTintedStyledAttributes(ThemeEnforcement.java:120)
        at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:424)
        at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:396)

...30 more

Edric
  • 24,639
  • 13
  • 81
  • 91
  • It's very difficult to debug a crash without a stack trace. Please see [Unfortunately MyApp has stopped. How can I solve this?](https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this) for Android-specific advice, and [What is a stack trace, and how can I use it to debug my application errors?](https://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors) for advice on what to do once you have the stack trace. If you still need help, please edit your question to include the stack trace. – Ryan M Mar 11 '20 at 09:11
  • Do you have that style in your app? – MMG Mar 11 '20 at 09:12
  • Style should come with material design. However I updated the question with stacktrace. – Klyc Creative Mar 11 '20 at 09:14

2 Answers2

0

update your library to 1.1.0

implementation 'com.google.android.material:material:1.1.0'

0

Looking into the stack trace, it's understood that you are not using the Material Theme:

Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).

You may add/change AppTheme in styles as follows:

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
    <!-- Add attributes here -->
</style>
npk
  • 1,512
  • 1
  • 13
  • 26