无法解析索引0处的属性

时间:2016-02-25 20:43:35

标签: android android-layout android-6.0-marshmallow

我整天都遇到了问题但没找到解决办法。

该应用程序在5.1上运行良好,但在6.1上它崩溃了。

我正在使用2个自定义主题来更改用户类型的应用颜色。

有人知道如何解决这个问题吗?

错误:

FATAL EXCEPTION: main
Process: ***.debug, PID: 7511
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.***.qa.debug/com.***.activity.HomeActivity}: android.view.InflateException: Binary XML file line #23: Binary XML file line #5: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #23: Binary XML file line #5: Error inflating class <unknown>
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
at android.app.Activity.setContentView(Activity.java:2172)
at com.***.activity.BaseActivity.onCreate(BaseActivity.java:54)
at com.***.activity.BaseMenuActivity.onCreate(BaseMenuActivity.java:88)
at com.***.activity.HomeActivity.onCreate(HomeActivity.java:87)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.view.InflateException: Binary XML file line #5: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:939)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:831)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:939)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:831)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
at android.app.Activity.setContentView(Activity.java:2172) 
at com.***.activity.BaseActivity.onCreate(BaseActivity.java:54) 
at com.***.activity.BaseMenuActivity.onCreate(BaseMenuActivity.java:88) 
at com.***.activity.HomeActivity.onCreate(HomeActivity.java:87) 
at android.app.Activity.performCreate(Activity.java:6251) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.reflect.InvocationTargetException

at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:939) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:831) 
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:939) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:831) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
at android.app.Activity.setContentView(Activity.java:2172) 
at com.***.activity.BaseActivity.onCreate(BaseActivity.java:54) 
at com.***.activity.BaseMenuActivity.onCreate(BaseMenuActivity.java:88) 
at com.***.activity.HomeActivity.onCreate(HomeActivity.java:87) 
at android.app.Activity.performCreate(Activity.java:6251) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/liner_layout_background.xml from drawable resource ID #0x7f0200fb
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2640)
at android.content.res.Resources.loadDrawable(Resources.java:2540)
at android.content.res.TypedArray.getDrawable(TypedArray.java:870)
at android.view.View.<init>(View.java:3954)
at android.view.ViewGroup.<init>(ViewGroup.java:573)
    at android.widget.LinearLayout.<init>(LinearLayout.java:203)
        at android.widget.LinearLayout.<init>(LinearLayout.java:199)
            at android.widget.LinearLayout.<init>(LinearLayout.java:195)
                at java.lang.reflect.Constructor.newInstance(Native Method) 
                at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
                at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
                at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
                at android.view.LayoutInflater.parseInclude(LayoutInflater.java:939) 
                at android.view.LayoutInflater.rInflate(LayoutInflater.java:831) 
                at android.view.LayoutInflater.parseInclude(LayoutInflater.java:939) 
                at android.view.LayoutInflater.rInflate(LayoutInflater.java:831) 
                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
                at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
                at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
                at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
                at android.app.Activity.setContentView(Activity.java:2172) 
                at com.***.activity.BaseActivity.onCreate(BaseActivity.java:54) 
                at com.***.activity.BaseMenuActivity.onCreate(BaseMenuActivity.java:88) 
                at com.***.activity.HomeActivity.onCreate(HomeActivity.java:87) 
                at android.app.Activity.performCreate(Activity.java:6251) 
                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                at android.os.Handler.dispatchMessage(Handler.java:102) 
                at android.os.Looper.loop(Looper.java:148) 
                at android.app.ActivityThread.main(ActivityThread.java:5417) 
                at java.lang.reflect.Method.invoke(Native Method) 
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 0: TypedV

linear_layout_background.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:state_enabled="true" 
        android:state_pressed="true"
        android:drawable="@color/blue_light_line" />

    <item android:state_enabled="true" 
        android:state_focused="true"
        android:drawable="@color/blue_light_line" />

    <item android:state_enabled="true"
        android:drawable="?attr/list_row_bg" />

</selector>

2 个答案:

答案 0 :(得分:4)

问题是因为我在drawables和selectors中使用了我的attr。我不知道为什么,但是使用棒棒糖这个代码运行正常并且使用旧的和新的apis不会。

报告的错误在于:https://code.google.com/p/android/issues/detail?id=26251

所以我要使用颜色引用复制我的所有drawable,并将它们指向Theme atributes。

这是问题所在:

<item android:state_enabled="true"
        android:drawable="?attr/list_row_bg" />

答案 1 :(得分:1)

你的第二种观点可能不是第一种观点的孩子。您可以尝试添加类似这样的样式文件。

<style name="MyTheme" parent="android:Theme">
...
</style>

您也可以查看此答案:Android: How to track down the origin of a InflateException?

他/她有同样的问题。