Binary XML file line #101: Error inflating class
app需要兼容多种分辨率的设备,一般的情况下,布局文件,都会提供多套出来,供自动匹配。
但调试修改布局文件的情况下,经常会报如下错误:
android.view.InflateException: Binary XML file line #101: Error inflating class
完整错误:
06-10 10:51:53.571: D/dalvikvm(9158): GC_FOR_ALLOC freed 38K, 4% free 9184K/9543K, paused 14ms, total 14ms 06-10 10:51:53.601: D/dalvikvm(9158): GC_CONCURRENT freed 6K, 3% free 12937K/13319K, paused 2ms+2ms, total 19ms 06-10 10:51:53.681: D/dalvikvm(9158): GC_FOR_ALLOC freed 3760K, 28% free 10848K/15047K, paused 12ms, total 12ms 06-10 10:51:53.711: W/ResourceType(9158): Failure getting entry for 0x7f020050 (t=1 e=80) in package 0 (error -75) 06-10 10:51:53.711: W/dalvikvm(9158): threadid=1: thread exiting with uncaught exception (group=0x40c19438) 06-10 10:51:53.721: E/AndroidRuntime(9158): FATAL EXCEPTION: main 06-10 10:51:53.721: E/AndroidRuntime(9158): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.foxhis.activity/com.foxhis.activity.LoginActivity}: android.view.InflateException: Binary XML file line #101: Error inflating class 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2067) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2092) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3520) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.app.ActivityThread.access$700(ActivityThread.java:133) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.os.Handler.dispatchMessage(Handler.java:99) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.os.Looper.loop(Looper.java:137) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.app.ActivityThread.main(ActivityThread.java:4800) 06-10 10:51:53.721: E/AndroidRuntime(9158): at java.lang.reflect.Method.invokeNative(Native Method) 06-10 10:51:53.721: E/AndroidRuntime(9158): at java.lang.reflect.Method.invoke(Method.java:511) 06-10 10:51:53.721: E/AndroidRuntime(9158): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797) 06-10 10:51:53.721: E/AndroidRuntime(9158): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:564) 06-10 10:51:53.721: E/AndroidRuntime(9158): at dalvik.system.NativeStart.main(Native Method) 06-10 10:51:53.721: E/AndroidRuntime(9158): Caused by: android.view.InflateException: Binary XML file line #101: Error inflating class 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.view.LayoutInflater.createView(LayoutInflater.java:613) 06-10 10:51:53.721: E/AndroidRuntime(9158): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 06-10 10:51:53.721: E/AndroidRuntime(9158): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:260) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.app.Activity.setContentView(Activity.java:1867) 06-10 10:51:53.721: E/AndroidRuntime(9158): at com.foxhis.activity.LoginActivity.onCreate(LoginActivity.java:74) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.app.Activity.performCreate(Activity.java:5008) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2031) 06-10 10:51:53.721: E/AndroidRuntime(9158): ... 12 more 06-10 10:51:53.721: E/AndroidRuntime(9158): Caused by: java.lang.reflect.InvocationTargetException 06-10 10:51:53.721: E/AndroidRuntime(9158): at java.lang.reflect.Constructor.constructNative(Native Method) 06-10 10:51:53.721: E/AndroidRuntime(9158): at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.view.LayoutInflater.createView(LayoutInflater.java:587) 06-10 10:51:53.721: E/AndroidRuntime(9158): ... 28 more 06-10 10:51:53.721: E/AndroidRuntime(9158): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f020050 a=-1 r=0x7f020050} 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.content.res.Resources.loadDrawable(Resources.java:1933) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.content.res.TypedArray.getDrawable(TypedArray.java:601) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.view.View.(View.java:3336) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.widget.TextView.(TextView.java:447) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.widget.Button.(Button.java:107) 06-10 10:51:53.721: E/AndroidRuntime(9158): at android.widget.Button.(Button.java:103) 06-10 10:51:53.721: E/AndroidRuntime(9158): ... 31 more
提示信息上面,会指明是哪一个Activity对应的Layout出现了布局。
按照提示去查看该layout,会发现,没有哪里出问题。这就怪了。
其实仔细查看,就会发现,不同分辨率下面,该布局文件所引用的资源,是有缺失的。
当调试分辨率是1024x768的layout时,我们添加了一张图片,但是我们习惯性的只是放在该分辨率下面的资源文件夹下面,那么就导致了,当我用1280x800这样的设备跑程序时,出现上述的问题。
解决方法:
把所有分辨率下面的资源文件中,都更新掉刚做的修改。添加文件时,所有分辨率下面都添加,删除时,都删除。做到同进退,上面这样的问题就不会出现了。
附上其他类似bug的解决方法:
http://blog.csdn.net/harry_helei/article/details/7265610
总结:
类似的XML错误,大部分都是因为资源文件的来回引用引起的。
只要留意资源文件的命名,引用,后缀等等,即可避免
相关推荐
liuxudong00 2020-11-19
wwzaqw 2020-11-11
lihaoxiang 2020-11-05
CrossingX 2020-11-04
xuegangic 2020-10-17
86417413 2020-11-25
83206733 2020-11-19
86276537 2020-11-19
83266337 2020-11-19
86256434 2020-11-17
zhouboxiao 2020-11-16
rise 2020-11-22
sssdssxss 2020-11-20
windle 2020-11-10
孙雪峰 2020-10-30
85477104 2020-11-17
xfcyhades 2020-11-20
cheidou 2020-11-19