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

后端 未结 30 1940
伪装坚强ぢ
伪装坚强ぢ 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:50

    You should copy the image files from the "drawable-24" folder to the "drawable" folder.

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

    For me it happened because I tried to mix xml vector graphics images with ordinary png in the same layout file,

    only after I replaced the xml vector graphics with pngs it started to work

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

    i had the same issue and it solved by removing drawable-v24 with (24) in front of images in drawable folder and replacing them with ordinary drawables.

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

    I know this thread is old, but still answering it so that no-one else should spend sleepless nights.

    I was refactoring an old project, whose layout files all contained hardcoded attributes such as android:maxLength = 500. So I decided to register it in my res/dimen file as <dimen name="max_length">500</dimen>.

    Finished refactoring almost 30 layout files with my res-value. Guess what? the next time I ran my project it started throwing the same InflateException.

    As a solution, needed to redo my all changes and keep all-those values as same as before.

    TLDR;

    step 1: All running good.

    step 2: To boost my maintenance I replaced android:maxLength = 500 with <dimen name="max_length">500</dimen> and android:maxLength = @dimen/max_length , that's where it all went wrong(crashing with InflateException).

    step 3: All running bad

    step 4: Re-do all my work by again replacing android:maxLength = @dimen/max_length with android:maxLength = 500.Everything got fixed.

    step 5: All running good.

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

    I had the same error in Crashlytics from a strange device: Motorola One Vision Android 5.1 and 20 GB (free) RAM, rooted This device comes originally with Android 9.0, 4 GB RAM

    Probably someone is trying to hack the app I'm currently developing and has problems dealing with multi-APKs. So drawables can't be found and the app delivers the crash

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

    I found the same error, and it took two days to identify what the error was.

    The error was simply because I was trying to use: android:background

    Rather than: app:srcCompat

    in an SVG file.

    In your case, I believe this is it

    <ImageView 
        android:scaleType="fitXY" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:src="@drawable/tour_11"      <-- the error is here !
     />
    

    I recommend using it this way

    add this to your build.gradle app

    android {  
       defaultConfig {  
         vectorDrawables.useSupportLibrary = true  
        }  
     }
    

    and

    <androidx.appcompat.widget.AppCompatImageView  <-- use **AppCompatImageView** not **ImageView**
            android:scaleType="fitXY" 
            android:layout_width="match_parent" 
            android:layout_height="match_parent" 
            app:srcCompat="@drawable/tour_11"
         />
    

    I hope this helps.

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