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

33

164

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>
Workday answered 22/12, 2010 at 19:35 Comment(1)
check this.this helps me!https://mcmap.net/q/151606/-android-tablelayout-errorGratifying
C
281

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.

Crimea answered 21/4, 2014 at 17:14 Comment(6)
@vnportnoy I have also same error when I remove imageForsaken
I believe I don't have any drawables in my applicationPleasure
Try to check your language bundle, probably a string resource is missing. This was causing a problem in my case.Favored
If your problem is with instrumentation tests, then try this: https://mcmap.net/q/151607/-android-testing-inflate-and-display-a-custom-toast-from-instrumentationAnthropogeography
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'Natheless
thanks @vnportnoy the issue was due to memory this helped meImpoverished
A
30

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

Alfons answered 9/6, 2016 at 14:7 Comment(3)
Once you activate that, you should always use app:srcCompatDundee
But this won't generate random crash.Bowfin
I use app:srcCompat with svg drawable and still get this errorCumshaw
W
24

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.

Workday answered 1/3, 2011 at 10:31 Comment(0)
A
14

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();
    }
Ara answered 21/2, 2017 at 1:50 Comment(0)
B
11

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.

Bragg answered 2/4, 2013 at 8:3 Comment(0)
C
11

I encountered the same bug and found the root reason is:

Use Application Context to inflate view.

Inflating with Activity Context fixed the bug.

Circle answered 9/9, 2015 at 4:8 Comment(1)
Cheers cox ... you saved my sorry assDaynadays
R
11

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.

Ratite answered 25/2, 2018 at 20:19 Comment(2)
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 thisBlakeley
I'm very happy to have helped you @BlakeleyRatite
A
6

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)

Accessary answered 11/5, 2015 at 15:43 Comment(0)
V
6

I had this error because i selected theme as Material theme. But as i was trying to run app on 4.4.2 it gave this error.

Solution : Select Theme_holo as theme

Volkan answered 3/11, 2015 at 18:56 Comment(1)
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: #37884177Naara
O
6

In case someone gets similar issues, I had such an issue while inflating the view:

View.inflate(getApplicationContext(), R.layout.my_layout, null)

fixed by replacing getApplicationContext() with this

Oared answered 31/3, 2018 at 15:5 Comment(0)
O
5

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).
Ostium answered 9/10, 2017 at 12:5 Comment(1)
Thanks! This helped me to find the problem!Graiae
I
5

For me, my issue was that I was

android:background="?attr/selectableItemBackground"

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

Izaguirre answered 25/10, 2019 at 11:29 Comment(1)
I had ConstraintLayout where I used this background tag. Removing the line solved the issue for me, thank you!Salmi
U
4

This link may help you. Try checking in your manifest for problems. If you can get it to happen again, post your entire stack trace so that we can see what the error actually is.

EDIT: I'm sure you've checked this, but what is on line 12 of the XML file you use for the TourActivity layout?

Ulcerate answered 22/12, 2010 at 20:35 Comment(6)
I have read this issue. This is not my case (at least I cannot see it). Adding stack to the question.Workday
Updated answer, can you post the XML? If you don't mind, post the entirety of the XML if it's not too large.Ulcerate
Added XML to the initial quesionWorkday
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?Ulcerate
No. Other files does not have merge of flipper but still have the same problem.Workday
Sometimes theme settings for the specific activity in the manifest can cause problems. That's what happened to me.Boden
W
3

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).

Woodsman answered 24/9, 2018 at 16:24 Comment(1)
I also had same case.Picasso
D
3

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

Drape answered 8/5, 2019 at 8:8 Comment(0)
E
3
  • I just solve this issue just delete your images from drawable(v24) and just paste it in drawable folder this works for me.

Earthshine answered 20/9, 2019 at 15:42 Comment(1)
Well, thank you for making it bold and clear.Homophony
L
2

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.

Leotie answered 14/6, 2016 at 7:58 Comment(0)
C
2

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!

Cowboy answered 20/5, 2017 at 19:8 Comment(1)
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.Curtsy
E
2

In my case,this error happen when I use the Floating action button and set android:backgroundTint="#000". Then just don't set backgroundTint and problem solved. Hope it's helpful for you.

Ean answered 5/7, 2017 at 9:54 Comment(1)
Thanks that was indeed the problem in my case. Need to use app:backgroundTint instead of android:backgroundTint.Memorial
J
2

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.

Johen answered 26/2, 2019 at 20:17 Comment(0)
L
2

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

Logotype answered 4/11, 2019 at 15:25 Comment(0)
S
1

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.

Spirited answered 6/11, 2018 at 7:40 Comment(0)
P
1

In my case I've to specify the complete package name of library UI component that I use in my layout file.

Piled answered 3/12, 2018 at 11:18 Comment(0)
F
1

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.

Facient answered 5/8, 2019 at 13:44 Comment(1)
That's because android:maxLength is not a dimension, you should use <integer name="max_length">500</integer> and android:maxLength="@integer/max_length".Dipnoan
N
1

just move image or shape

  • drawable-v24 to drawable folder

    enter image description here

InflateException:

android.view.InflateException: Binary XML file line #32: Error inflating class androidx.appcompat.widget.SearchView
    at android.view.LayoutInflater.createView(LayoutInflater.java:633)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
    at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:126)
    at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:95)
    at com.foamkart.Fragment.SearchFragment.onCreateView(SearchFragment.kt:37)
Nazario answered 5/1, 2021 at 5:41 Comment(0)
G
0

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!!

Gazpacho answered 4/5, 2018 at 10:48 Comment(0)
C
0

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..

Chaudoin answered 23/7, 2018 at 6:55 Comment(0)
N
0

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}
Nautch answered 24/8, 2018 at 14:12 Comment(0)
E
0

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

Estuarine answered 4/3, 2019 at 8:29 Comment(0)
A
0

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

Aggi answered 30/4, 2020 at 8:30 Comment(0)
C
0

I had the same error on Kitkat which was because i had android:tint on one of the imageViews. It would work fine on Lollipop but crash on Kikkat with Error Inflating class .

Fixed it by using app:tint on the AppCompatImageView which i was dealing with.

Curvet answered 1/9, 2020 at 15:15 Comment(0)
I
0

I solved this by updating my app theme to inherit from material components.

<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight">
    <!-- ... -->
</style>
Inexorable answered 27/9, 2020 at 11:9 Comment(0)
C
0

If you are using Navigation Component and trying to inflate androidx.fragment.app.FragmentContainerView, make sure you set an startDestination on your Nav Graph!

Cancer answered 27/12, 2021 at 3:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.