android.view.InflateException: Binary XML file line #0: Error inflating class Button

后端 未结 6 996
陌清茗
陌清茗 2021-02-12 14:49

I am following a course on Audacity, and decided to type out all the code, but then I run into an error when I try run the app.

I get the following error:



        
相关标签:
6条回答
  • 2021-02-12 15:26

    I have got the same issue and I have resolved finally Opening the gradle.properties and added following line:

    android.enableAapt2=false
    

    Hope this helps you.

    0 讨论(0)
  • 2021-02-12 15:33

    the button selector is the cause of the problem .. if you read the remaining of the exception, the root cause will be mentioned .. as resource id can't be found !

    you have to change your button_selector.xml from:

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:color="#999999" android:state_enabled="false"/>
        <item android:color="@color/colorAccent" android:state_enabled="true"/>
    </selector>
    

    to:

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="#999999" android:state_enabled="false"/>
        <item android:drawable="@color/colorAccent" android:state_enabled="true"/>
    </selector>
    

    and it will work fine isA.

    0 讨论(0)
  • 2021-02-12 15:36

    In my case the background xmls where not inside one drawable directory. I added all of them in drawable hdpi folder and then rebuild the project. That resolved this issue.

    This worked for me!

    0 讨论(0)
  • 2021-02-12 15:37

    May be you declare the drawable file into v21 or v24 folder to change this select the button_selector.xml file go to the show in menu option file select the cut button_selector.xml file and move into the drawable folder and paste it.

    0 讨论(0)
  • 2021-02-12 15:38

    Maybe this help anyone > I got similar crash

    InflateException: Binary XML file line #0: Error inflating class EditText

    in Android 8.0 and 8.1 in release apk due to xml fonts cause I didn't use latest support libs, I update support library version and it's fixed.

    xml having

    <EditText
            android:id="@+id/editEmail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="@font/sanfranciscodisplay_medium"
            android:hint="@string/enter_email_address"
            android:lines="1"
            android:inputType="textEmailAddress"
            android:layout_centerHorizontal="true"/>
    

    My gradle configs

    BUILD_TOOLS_VER = '26.0.2'
    
    TARGET_SDK_VER = 26
    MIN_SDK_VER = 19
    
    SUPPORT_LIBS_VER = '26.1.0' -> '27.0.2' (fix here)
    GOOGLE_SERVICES_VER = '11.4.0' -> '11.8.0'
    
    0 讨论(0)
  • 2021-02-12 15:40

    Have you tried adding in gradle.properties file this line below ?

     android.enableAapt2=false
    

    and then restarting the Gradle daemon command line by running

    ./gradlew --stop
    

    https://developer.android.com/studio/releases/gradle-plugin.html#optimizations

    0 讨论(0)
提交回复
热议问题