Error inflating class com.google.android.material.textfield.TextInputLayout Android Studio 3.5

3.4k Views Asked by At

I am using android studio 3.5 and this is the error i am getting for my TextInputLayout. The layout was working from the beginning but after sometime now the app crashes with the error

android.view.InflateException: Binary XML file line #18: Binary XML file line #18: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class com.google.android.material.textfield.TextInputLayout
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:658)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:801)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:874)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:877)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)

My xml for the layout is

<com.google.android.material.textfield.TextInputLayout
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        app:errorEnabled="true"
        app:hintEnabled="true"
        android:theme="@style/TextLabel">


        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/phone_number"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:ems="15"
            android:hint="@string/phone_number"
            android:inputType="number" />


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

My Styles.xml is :

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />


<style name="TextLabel" parent="Widget.MaterialComponents.TextInputLayout.FilledBox">

    <item name="colorControlActivated">@color/colorPrimary</item>
</style>

I have also implemented the following dependencies but it did not help

implementation 'com.google.android.material:material:1.1.0-alpha06'
implementation 'com.google.android.material:material:1.0.0'

Could there also be an error with this new androidx as i have been receiving the same errors on different layouts which would have worked before and then after some time the app starts working again?

1

There are 1 best solutions below

0
Weikardzaena On BEST ANSWER

Your app theme is inheriting from AppCompat, but you're using Material components. Try changing your app theme to inherit from Theme.MaterialComponents.Light.NoActionBar instead. That should do the trick.