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

后端 未结 30 1982
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 13:48

I am receiving many errors of kind displayed in the subj. These errors seems to be occasional and I cannot reproduce them. From stack I can learn that such error may occurs

相关标签:
30条回答
  • 2020-11-22 14:34

    For me, my issue was that I was

    android:background="?attr/selectableItemBackground"
    

    To a LinearLayout background, once I removed it the test passed.

    0 讨论(0)
  • 2020-11-22 14:37

    I had this problem just now and managed to figure out what it was. Was referencing a colour in my values that was causing problems. So defined it manually instead of using one from the dropdown suggestions.Then it worked!

    0 讨论(0)
  • 2020-11-22 14:38

    Solved it by moving all my drawable items from drawable-v24 to drawable

    0 讨论(0)
  • 2020-11-22 14:38

    I had faced the same issue, I had used view tag in xml instead of View. Replacing to View class fixed the issue.

    Hope it helps for you too..

    0 讨论(0)
  • 2020-11-22 14:39

    We need to check API Version. I used to give background color to my LinearLayout like

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/as_royalblue"
            android:orientation="vertical"></LinearLayout>
    

    for sure I had the same error, as_royalblue.xml inside drawable folder

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <gradient
            android:angle="90"
            android:endColor="@color/royalblue_s"
            android:startColor="@color/royalblue_e" />
    </shape>
    

    and how I fixed it, actually it seems Api problem so we need to check the api level if it is above API 24 so we are able to use the way we like. But if it is under 24 we need to avoid usage, juts give a normal color or one color not color gradential mixed one.

    fun checkAPI_N(): Boolean {
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N)
                return true
            else
                return false
        }
    

    give id to your linearlayouts and set backgrounds if its ok

     if(UtilKotlin.checkAPI_N()){
                linlay_act_menu_container.setBackgroundResource(R.drawable.a_6)
                linlay_act_menu_logo.setBackgroundResource(R.drawable.as_strain)
            }else {//todo normal color background setting}
    
    0 讨论(0)
  • 2020-11-22 14:40

    For me, the error message was actually insufficient in the log cat, so here's what I did to figure out what caused the problem:

    (In the log cat error message, it said the error occurred while inflating a specific layout in my HomeFragment.java)

    1. I put a breakpoint just before the layout was inflated
    2. I ran the application in debug mode until it reached that specific breakpoint
    3. I selected the line with my cursor and ran Evaluate expression on it:
      • Run > Evaluate Expression or alt - F8
    4. The result showed me more information about the source of the problem, which in my case, was a drawable file using tools:targetApi="lollipop" (the bug only occurred on older devices).
    0 讨论(0)
提交回复
热议问题