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

匿名 (未验证) 提交于 2019-12-03 01:55:01

问题:

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

               

回答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 this 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 your drawables images are just the minimum necessary for your layout.



回答2:

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.



回答3:

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



回答4:

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.



回答5:

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?



回答6:

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

Use Application Context to inflate view.

Inflating with Activity Context fixed the bug.



回答7:

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



回答8:

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)



回答9:

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();     } 


回答10:

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.



回答11:

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!



回答12:

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.



回答13:

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


回答14:

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 one: android:background

Rather than: app:srcCompat

in an SVG file.

In your case, I believe this is it

I hope this helps.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!