本文共 10011 字,大约阅读时间需要 33 分钟。
参考:
问题:
--------- beginning of crash05-23 18:36:40.164 3557-3557/com.lidan.xiao.danquestion E/AndroidRuntime: FATAL EXCEPTION: main Process: com.lidan.xiao.danquestion, PID: 3557 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lidan.xiao.danquestion/com.lidan.xiao.danquestion.activity.QuestionActivity}: android.view.InflateException: Binary XML file line #10: Error inflating classat android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392) at android.app.ActivityThread.access$800(ActivityThread.java:153) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5293) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class at android.view.LayoutInflater.createView(LayoutInflater.java:633) at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741) at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) at android.view.LayoutInflater.rInflate(LayoutInflater.java:809) at android.view.LayoutInflater.inflate(LayoutInflater.java:504) at android.view.LayoutInflater.inflate(LayoutInflater.java:414) at android.view.LayoutInflater.inflate(LayoutInflater.java:365) at com.lidan.xiao.danquestion.activity.QuestionActivity.createView(QuestionActivity.java:176) at com.lidan.xiao.danquestion.activity.QuestionActivity.access$300(QuestionActivity.java:39) at com.lidan.xiao.danquestion.activity.QuestionActivity$2.getView(QuestionActivity.java:168) at android.widget.AdapterViewAnimator.showOnly(AdapterViewAnimator.java:548) at android.widget.AdapterViewAnimator.setAdapter(AdapterViewAnimator.java:971) at android.widget.AdapterViewFlipper.setAdapter(AdapterViewFlipper.java:144) at com.lidan.xiao.danquestion.activity.QuestionActivity.initView(QuestionActivity.java:172) at com.lidan.xiao.danquestion.activity.QuestionActivity.onCreate(QuestionActivity.java:72) at android.app.Activity.performCreate(Activity.java:5990) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2280) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392) at android.app.ActivityThread.access$800(ActivityThread.java:153) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5293) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:288) at android.view.LayoutInflater.createView(LayoutInflater.java:607) at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741) at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) at android.view.LayoutInflater.rInflate(LayoutInflater.java:809) at android.view.LayoutInflater.inflate(LayoutInflater.java:504) at android.view.LayoutInflater.inflate(LayoutInflater.java:414) at android.view.LayoutInflater.inflate(LayoutInflater.java:365) at com.lidan.xiao.danquestion.activity.QuestionActivity.createView(QuestionActivity.java:176) at com.lidan.xiao.danquestion.activity.QuestionActivity.access$300(QuestionActivity.java:39) at com.lidan.xiao.danquestion.activity.QuestionActivity$2.getView(QuestionActivity.java:168) at android.widget.AdapterViewAnimator.showOnly(AdapterViewAnimator.java:548) at android.widget.AdapterViewAnimator.setAdapter(AdapterViewAnimator.java:971) at android.widget.AdapterViewFlipper.setAdapter(AdapterViewFlipper.java:144) at com.lidan.xiao.danquestion.activity.QuestionActivity.initView(QuestionActivity.java:172) at com.lidan.xiao.danquestion.activity.QuestionActivity.onCreate(QuestionActivity.java:72) at android.app.Activity.performCreate(Activity.java:5990) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2280) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392) at android.app.ActivityThread.access$800(ActivityThread.java:153) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5293) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) Caused by: android.content.res.Resources$NotFoundException: Resource "android:style/Widget.Material.Light.ProgressBar.Horizontal" (10302b8) is not a Drawable (color or path): TypedValue{t=0x1/d=0x10302b8 a=-1 r=0x10302b8} at android.content.res.Resources.loadDrawableForCookie(Resources.java:2441) at android.content.res.Resources.loadDrawable(Resources.java:2381) at android.content.res.TypedArray.getDrawable(TypedArray.java:749) at android.widget.ProgressBar. (ProgressBar.java:267) at android.widget.ProgressBar. (ProgressBar.java:253) at android.widget.ProgressBar. (ProgressBar.java:249) at java.lang.reflect.Constructor.newInstance(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:288) at android.view.LayoutInflater.createView(LayoutInflater.java:607) at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741) at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) at android.view.LayoutInflater.rInflate(LayoutInflater.java:809) at android.view.LayoutInflater.inflate(LayoutInflater.java:504) at android.view.LayoutInflater.inflate(LayoutInflater.java:414) at android.view.LayoutInflater.inflate(LayoutInflater.java:365) at com.lidan.xiao.danquestion.activity.QuestionActivity.createView(QuestionActivity.java:176) at com.lidan.xiao.danquestion.activity.QuestionActivity.access$300(QuestionActivity.java:39) at com.lidan.xiao.danquestion.activity.QuestionActivity$2.getView(QuestionActivity.java:168) at android.widget.AdapterViewAnimator.showOnly(AdapterViewAnimator.java:548) at android.widget.AdapterViewAnimator.setAdapter(AdapterViewAnimator.java:971) at android.widget.AdapterViewFlipper.setAdapter(AdapterViewFlipper.java:144) at com.lidan.xiao.danquestion.activity.QuestionActivity.initView(QuestionActivity.java:172) at com.lidan.xiao.danquestion.activity.QuestionActivity.onCreate(QuestionActivity.java:72) at android.app.Activity.performCreate(Activity.java:5990) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2280) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392) at android.app.ActivityThread.access$800(ActivityThread.java:153) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5293) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
QuestionActivity.java:176)对应的是
root = LayoutInflater.from(QuestionActivity.this).inflate(R.layout.queitem, null);
从而看出是queitem.xml中问题,这个文件有两个(一般和V21,SDK5.0)。在其中搜Widget.Material.Light.ProgressBar.Horizontal。(V21中存在)
这句话android:progressDrawable="@android:style/Widget.Material.Light.ProgressBar.Horizontal"为什么会报错呢?
之前能用,现在不能,应该是android新旧版本不兼容bug。网上正确用法如下。
原因:为什么没有模拟器没有报错 是因为API19不会去引用这个布局所以不会报错
之所以运行才报错 是因为这只是一个运行时异常 且符合编译规则,只有运行后才会出错。API5.0的模拟器就会报错。原代码:
改为
转载地址:http://vcaab.baihongyu.com/