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

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

    My picture size is only 14Kb but the problem is that the designer gave me 1011px x 1819px (resolution too high hence causing the InflateException)

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

    I know the question is already answered but still I'm posting with thought that may someone run into this kind of problem.

    In my case problem is i'm loading my application to phone which refer layouts from res/layout/ folder and values for @dimens from res/values/dimens here it's font_22 which it's trying to access and it's define in res/values-xlarge/dimens.

    I'm actually updating UI of existing project.

    I ran into this problem because I'm using IDE Eclipse where I ctrl+space for hint while writing xml for layout folder it displays all values from values as well as values-xlarge folder regardless of for which folder I'm writing.

    I also know that the values in both files should be same to mapped for different screens.

    Hope this may help someone run into this kind of silly problem.

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

    I know it is an answered question, but I do not see the cause that I faced.

    It was that Android Studio placed my drawables in /drawable-V24 My emulator is API 23. So, eventually it can not find it.

    The solution was to move all drawables to /drawable folder (no -24).

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

    I had the same error and I solved moving my drawables from the folder drawable-mdpi to the folder drawable. Took me some time to realize because in Eclipse everything worked perfectly while in Android Studio I got these ugly runtime errors.

    Edit note: If you are migrating from eclipse to Android Studio and your project is coming from eclipse it may happen, so be careful that in Android Studio things a little differs from eclipse.

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

    I also faced a similar issue. While for anyone this may be an issue of various bad usages in Code such as

    1. Wrong Layout tag in XML
    2. Loading of heavy resource directly into ImageView resulting in OOM
    3. Issues with usage of styles.

    One most ignored factor may be usage of correct Context while inflating views. Please check that you are not using ApplicationContext where an Activity context is required. While, ApplicationContext may not end up in error always, but depending upon your view hierarchy it may be crucial.

    I resolved my issue with a BAD context (using ApplicationContext instead of Activity in a span of 4 days! So try if that solves. Happy Coding!!

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

    I had same error when I ran my app on API lvl 16 (26 was fine). It was because I used ?attrr/colorAccent in my shape drawable:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
    
        <corners android:radius="8dp" />
    
        <solid android:color="@attr/colorAccent" />
    
    </shape>
    

    Replacing that with a regular color fixed my problem.

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