异常 - 无法解析索引6处的属性:TypedValue

时间:2016-04-06 12:58:40

标签: android

我看到以下异常:

04-06 13:35:58.498  4219  4219 E AndroidRuntime: android.view.InflateException: Binary XML file line #17: Failed to resolve attribute at index 6: TypedValue{t=0x3/d=0x46 "res/color/abc_secondary_text_material_dark.xml" a=2 r=0x7f0e00e5}
04-06 13:35:58.498  4219  4219 E AndroidRuntime:    at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
04-06 13:35:58.498  4219  4219 E AndroidRuntime:    at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
04-06 13:35:58.498  4219  4219 E AndroidRuntime:    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
04-06 13:35:58.498  4219  4219 E AndroidRuntime:    at android.support.v7.internal.view.menu.MenuPopupHelper$MenuAdapter.getView(MenuPopupHelper.java:374)
04-06 13:35:58.498  4219  4219 E AndroidRuntime:    at android.support.v7.internal.view.menu.MenuPopupHelper.measureContentWidth(MenuPopupHelper.java:223)
04-06 13:35:58.498  4219  4219 E AndroidRuntime:    at android.support.v7.internal.view.menu.MenuPopupHelper.tryShow(MenuPopupHelper.java:157)
04-06 13:35:58.498  4219  4219 E AndroidRuntime:    at android.support.v7.widget.ActionMenuPresenter$OpenOverflowRunnable.run(ActionMenuPresenter.java:781)
04-06 13:35:58.498  4219  4219 E AndroidRuntime:    at android.os.Handler.handleCallback(Handler.java:739)
04-06 13:35:58.498  4219  4219 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:95)
04-06 13:35:58.498  4219  4219 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:148)
04-06 13:35:58.498  4219  4219 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:5417)
04-06 13:35:58.498  4219  4219 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
04-06 13:35:58.498  4219  4219 E AndroidRuntime:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
04-06 13:35:58.498  4219  4219 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
04-06 13:35:58.498  4219  4219 E AndroidRuntime: Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x3/d=0x46 "res/color/abc_secondary_text_material_dark.xml" a=2 r=0x7f0e00e5}
04-06 13:35:58.498  4219  4219 E AndroidRuntime:    at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:705)
04-06 13:35:58.498  4219  4219 E AndroidRuntime:    at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:6890)
04-06 13:35:58.498  4219  4219 E AndroidRuntime:    at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:7071)
04-06 13:35:58.498  4219  4219 E AndroidRuntime:    at android.widget.FrameLayout$LayoutParams.<init>(FrameLayout.java:446)
04-06 13:35:58.498  4219  4219 E AndroidRuntime:    at android.widget.FrameLayout.generateLayoutParams(FrameLayout.java:386)
04-06 13:35:58.498  4219  4219 E AndroidRuntime:    at android.widget.FrameLayout.generateLayoutParams(FrameLayout.java:385)
04-06 13:35:58.498  4219  4219 E AndroidRuntime:    at android.view.LayoutInflater.inflate(LayoutInflater.java:502)

当我点击工具栏中的菜单按钮时,现在发生了两次。不幸的是,这似乎是非常不可预测的,并且在很多尝试中发生了两次。我的菜单如下:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto">

  <item android:id="@+id/menu_action_show_project_startup"
    android:title="@string/menu_action_project_intro"
    android:orderInCategory="300"
    app:showAsAction="never"/>

  <item android:id="@+id/menu_action_report_issue"
      android:title="@string/menu_action_report_issue"
      android:orderInCategory="300"
      app:showAsAction="never"/>

  <item android:id="@+id/menu_action_toggle_mobile_data"
    android:checkable="true"
    android:checked="true"
    android:title="@string/menu_action_toggle_mobile_data"
    android:orderInCategory="500"
    app:showAsAction="never"/>

  <item android:id="@+id/menu_action_logout"
    android:title="@string/menu_action_logout"
    android:orderInCategory="600"
    app:showAsAction="never"/>

</menu>

我看了一个类似的问题 - Android XML: RuntimeException: Failed to resolve attribute at index 6 - 但我的问题似乎并非来自FAB按钮,我在我的应用中使用了AppCompat。

4 个答案:

答案 0 :(得分:4)

我认为这是Google的错误报告,请确保使用正确的主题

https://code.google.com/p/android/issues/detail?id=152141

答案 1 :(得分:4)

基于TaoBit的上述解决方案,我意识到问题在于我的主题在Marshmallow中是不可接受的。所以我换了

<style name="Dark.Overlay" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="android:background">?attr/colorPrimary</item>
</style>

这一切都有效。感谢TaoBit提示。你节省了2天的工作和很多头痛。我很喜欢这一天。

<style name="MyToolbar" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:background">#FF0000</item>
    <item name="android:textColorPrimary">#FFFFFF</item>
</style>

答案 2 :(得分:2)

我遇到了这个问题,这是因为我的dimens.xml文件中包含以下行:

<dimen name="viewname_padding_top">?actionBarSize</dimen>

因此我将其替换为:

<dimen name="viewname_padding_top">@dimen/abc_action_bar_default_height_material</dimen>

答案 3 :(得分:0)

我是我的情况,我在colors.xml中

<color name="textColorTitle">?themeColorPrimary</color>

当我将其设置为实际值而不是属性时,它就起作用了。

<color name="textColorTitle">@color/colorPrimary</color>