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

343,782

Solution 1

The inflate exception is not actually the problem but really comes from another deeper issue in your layout that is then wrapped in an InflateException. A common issue is an out of memory exception when trying to inflate an ImageView loading a drawable resource. If one of these resources has a high pixel resolution it would take a lot of memory causing then an inflate exception.

So basically verify that the pixel resolution in all your image drawables is just the minimum necessary for your layout.

Solution 2

This can also happen if you use a VectorDrawable using support library and forgot to use app:srcCompat instead of android:src

Exact error is: Binary XML file line #XX: Error inflating class ImageView

See that link

Solution 3

ViewFlipper loads all images into memory during layout inflating. Because my images are big it takes many memory, I replaced ViewFlipper with ImageSwitcher which can change the images with animation like ViewFlipper but it loads only one image at the time.

Solution 4

I had the same error when creating custom view with only one constructor, try to define all constructor for your custom views.

   public CustomWebView(Context context) {
        super(context);
        init();
    }

    public CustomWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public CustomWebView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

Solution 5

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.

Share:
343,782

Related videos on Youtube

Solvek
Author by

Solvek

Updated on December 27, 2021

Comments

  • Solvek
    Solvek over 2 years

    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 for my different layout resources. The line of XML is also varying.

    Can anybody explain why this error occurs? And what I can do to fix this problem?

    Stack

    =============================================================
    
    com.fsp.android.f generated the following exception:
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fsp.android.f/com.life360.android.ui.tour.TourActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class <unknown>
    
    --------- Stack trace ---------
    1. android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2649)
    2. android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2674)
    3. android.app.ActivityThread.access$2200(ActivityThread.java:131)
    4. android.app.ActivityThread$H.handleMessage(ActivityThread.java:1975)
    5. android.os.Handler.dispatchMessage(Handler.java:99)
    6. android.os.Looper.loop(Looper.java:123)
    7. android.app.ActivityThread.main(ActivityThread.java:4702)
    8. java.lang.reflect.Method.invokeNative(Native Method)
    9. java.lang.reflect.Method.invoke(Method.java:521)
    10. com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    11. com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    12. dalvik.system.NativeStart.main(Native Method)
    -------------------------------
    
    ----------- Cause -----------
    android.view.InflateException: Binary XML file line #12: Error inflating class <unknown>
    
    1. android.view.LayoutInflater.createView(LayoutInflater.java:513)
    2. com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    3. android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
    4. android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
    5. android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
    6. android.view.LayoutInflater.inflate(LayoutInflater.java:382)
    7. android.view.LayoutInflater.inflate(LayoutInflater.java:320)
    8. android.view.LayoutInflater.inflate(LayoutInflater.java:276)
    9. com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:208)
    10. android.app.Activity.setContentView(Activity.java:1629)
    11. com.solvek.sample.ui.BaseActivity.onCreate(BaseActivity.java:23)
    12. com.solvek.sample.ui.tour.TourActivity.onCreate(TourActivity.java:161)
    13. android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    14. android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2587)
    15. android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2674)
    16. android.app.ActivityThread.access$2200(ActivityThread.java:131)
    17. android.app.ActivityThread$H.handleMessage(ActivityThread.java:1975)
    18. android.os.Handler.dispatchMessage(Handler.java:99)
    19. android.os.Looper.loop(Looper.java:123)
    20. android.app.ActivityThread.main(ActivityThread.java:4702)
    21. java.lang.reflect.Method.invokeNative(Native Method)
    22. java.lang.reflect.Method.invoke(Method.java:521)
    23. com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    24. com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    25. dalvik.system.NativeStart.main(Native Method)
    -----------------------------
    
    -------- Environment --------
    Time =2010-12-20 08:27:35 AM
    Device =tmobile/htc_espresso/espresso/espresso:2.1-update1/ERE27/216830:user/release-keys
    Make =HTC
    Model =T-Mobile myTouch 3G Slide
    Product =htc_espresso
    App =com.fsp.android.f, version 2.0.9 (build 1232)
    

    Here is a result of XML, however such error occurs in other xmls

    <?xml version="1.0" encoding="utf-8"?>
    <merge xmlns:android="http://schemas.android.com/apk/res/android">
        <ViewFlipper android:layout_gravity="fill" android:id="@+id/flipper" android:layout_height="fill_parent" android:layout_width="fill_parent">
            <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_1"/>
            <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_2"/>
            <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_3"/>
            <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_4"/>
            <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_5"/>
            <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_6"/>
            <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_7"/>
            <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_8"/>
            <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_9"/>
            <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_10"/>
            <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_11"/>
        </ViewFlipper>
    
        <LinearLayout android:id="@+id/exit_bar" android:layout_gravity="top" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/blue_bar" android:visibility="invisible">
            <Button android:background="@drawable/orange_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center" android:textStyle="bold" android:textColor="#000000" android:shadowColor="#ffffff" android:shadowRadius="1.6" android:shadowDx="1.5" android:shadowDy="1.3" android:id="@+id/exit_tour_btn" android:text="Exit" android:layout_marginLeft="20dip"/>
            <TextView android:layout_height="wrap_content" android:textColor="#ffffff" android:layout_gravity="center" android:layout_width="110dip" android:layout_marginLeft="20dip" android:textSize="16dip" android:textStyle="bold" android:text="Life360 Tour"/>
    
        </LinearLayout>
    
        <Button style="@style/BlueBtn" android:text="Continue" android:layout_marginTop="40dip" android:id="@+id/continue_btn" android:visibility="gone" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center" />
    
        <FrameLayout android:id="@+id/bottom_bar" android:layout_gravity="bottom" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/blue_bar" android:visibility="invisible">
            <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/left" android:layout_gravity="left|center" android:background="@drawable/tour_left" android:layout_marginLeft="10dip"/>
            <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/right" android:layout_gravity="right|center" android:background="@drawable/tour_right" android:layout_marginRight="10dip"/>               
        </FrameLayout>
    </merge>
    
  • Solvek
    Solvek over 13 years
    I have read this issue. This is not my case (at least I cannot see it). Adding stack to the question.
  • Kevin Coppock
    Kevin Coppock over 13 years
    Updated answer, can you post the XML? If you don't mind, post the entirety of the XML if it's not too large.
  • Solvek
    Solvek over 13 years
    Added XML to the initial quesion
  • Kevin Coppock
    Kevin Coppock over 13 years
    Hmm, unfortunately I have no experience with using merge or ViewFlipper...Do all of the XML files that this happens with use merge or ViewFlipper?
  • Solvek
    Solvek over 13 years
    No. Other files does not have merge of flipper but still have the same problem.
  • Harin Kaklotar
    Harin Kaklotar over 8 years
    @vnportnoy I have also same error when I remove image
  • Arturas M
    Arturas M over 8 years
    I believe I don't have any drawables in my application
  • Nick.D
    Nick.D about 8 years
    Sometimes theme settings for the specific activity in the manifest can cause problems. That's what happened to me.
  • Mohammed Subhi Sheikh Quroush
    Mohammed Subhi Sheikh Quroush about 8 years
    Try to check your language bundle, probably a string resource is missing. This was causing a problem in my case.
  • Katedral Pillon
    Katedral Pillon almost 8 years
    My problem may be similar to yours as I am seeing the crash only on 4.2.2. But where do I change from Material theme to Theme_holo? I don't see the keyword Material in my styles.xml or v21/styles.xml. See my question: stackoverflow.com/questions/37883677/…
  • Mohamed ALOUANE
    Mohamed ALOUANE over 7 years
    Once you activate that, you should always use app:srcCompat
  • Jerry Destremps
    Jerry Destremps over 7 years
    If your problem is with instrumentation tests, then try this: stackoverflow.com/q/24904445
  • Menna-Allah Sami
    Menna-Allah Sami over 7 years
    But this won't generate random crash.
  • Subho
    Subho almost 7 years
    After remove the imageview from my xml still the error happen in classpath 'com.android.tools.build:gradle:3.0.0-alpha2' and compile 'com.android.support.constraint:constraint-layout:1.0.2'
  • Rafael
    Rafael over 5 years
    I also had same case.
  • Drago
    Drago almost 5 years
    Thanks that was indeed the problem in my case. Need to use app:backgroundTint instead of android:backgroundTint.
  • Aayushi
    Aayushi about 4 years
    thanks @vnportnoy the issue was due to memory this helped me
  • Sergey Stasishin
    Sergey Stasishin almost 4 years
    Thanks! This helped me to find the problem!
  • Johnny Five
    Johnny Five over 3 years
    I use app:srcCompat with svg drawable and still get this error
  • sidon
    sidon over 3 years
    That's because android:maxLength is not a dimension, you should use <integer name="max_length">500</integer> and android:maxLength="@integer/max_length".
  • shadygoneinsane
    shadygoneinsane over 3 years
    ohh my my I have been trying to identify this in a custom view and was clueless about the error that android was throwing.. many many thanks for posting this
  • Williaan Lopes
    Williaan Lopes over 3 years
    I'm very happy to have helped you @shadygoneinsane
  • baskInEminence
    baskInEminence about 3 years
    I had ConstraintLayout where I used this background tag. Removing the line solved the issue for me, thank you!
  • Sharan
    Sharan about 3 years
    Well, thank you for making it bold and clear.
  • petestmart
    petestmart almost 2 years
    Similarly, I received this error because a color was missing from my res/values/colors.xml file. We have a defined toolbar color that was empty:<color name="toolbar_background_color"></color>. We use a brand file that changes from customer to customer. Turned out to be a bug in another repo that generates this file. Nonetheless, the missing color code was the culprit.