三星Galaxy / Holoeverywhere - 资源不是ColorStateList(颜色或路径)

时间:2013-09-03 23:02:53

标签: android galaxy android-holo-everywhere

我在Samsung Galaxy Ace / Y / Pocket / Mini上遇到了以下崩溃。它在所有其他设备上运行良好。崩溃只发生在Android 2.3.5或2.3.6

堆栈跟踪中没有引用我的代码。它似乎来自我没有定制的菜单布局。

我怀疑这是Galaxy OS的一个错误。但无法确认。

更重要的是,我能做些什么来避免或缓解这个错误?

android.view.InflateException: Binary XML file line #45: Error inflating class 
at org.holoeverywhere.LayoutInflater._createView(SourceFile:382)
at org.holoeverywhere.LayoutInflater.onCreateView(SourceFile:594)
at org.holoeverywhere.LayoutInflater.createViewFromTag(SourceFile:444)
at org.holoeverywhere.LayoutInflater.rInflate(SourceFile:731)
at org.holoeverywhere.LayoutInflater.rInflate(SourceFile:734)
at org.holoeverywhere.LayoutInflater.inflate(SourceFile:538)
at org.holoeverywhere.LayoutInflater.inflate(SourceFile:488)
at com.android.internal.view.menu.MenuItemImpl.createItemView(MenuItemImpl.java:592)
at com.android.internal.view.menu.MenuItemImpl.getItemView(MenuItemImpl.java:577)
at com.android.internal.view.menu.MenuBuilder$MenuAdapter.getView(MenuBuilder.java:1173)
at android.widget.AbsListView.obtainView(AbsListView.java:1592)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1251)
at android.widget.ListView.onMeasure(ListView.java:1162)
at android.view.View.measure(View.java:8313)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
at android.view.View.measure(View.java:8313)
at android.view.ViewRoot.performTraversals(ViewRoot.java:845)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
at org.holoeverywhere.LayoutInflater._createView(SourceFile:358)
... 26 more Caused by: android.content.res.Resources$NotFoundException: Resource is not a ColorStateList (color or path): TypedValue{t=0x1/d=0x7f0d014c a=3 r=0x7f0d014c}
at android.content.res.Resources.loadColorStateList(Resources.java:1804)
at android.content.res.TypedArray.getColorStateList(TypedArray.java:342)
at android.widget.TextView.(TextView.java:445)
at org.holoeverywhere.widget.TextView.(SourceFile:133)
at org.holoeverywhere.widget.TextView.(SourceFile:129)
... 29 more java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
at org.holoeverywhere.LayoutInflater._createView(SourceFile:358)
at org.holoeverywhere.LayoutInflater.onCreateView(SourceFile:594)
at org.holoeverywhere.LayoutInflater.createViewFromTag(SourceFile:444)
at org.holoeverywhere.LayoutInflater.rInflate(SourceFile:731)
at org.holoeverywhere.LayoutInflater.rInflate(SourceFile:734)
at org.holoeverywhere.LayoutInflater.inflate(SourceFile:538)
at org.holoeverywhere.LayoutInflater.inflate(SourceFile:488)
at com.android.internal.view.menu.MenuItemImpl.createItemView(MenuItemImpl.java:592)
at com.android.internal.view.menu.MenuItemImpl.getItemView(MenuItemImpl.java:577)
at com.android.internal.view.menu.MenuBuilder$MenuAdapter.getView(MenuBuilder.java:1173)
at android.widget.AbsListView.obtainView(AbsListView.java:1592)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1251)
at android.widget.ListView.onMeasure(ListView.java:1162)
at android.view.View.measure(View.java:8313)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
at android.view.View.measure(View.java:8313)
at android.view.ViewRoot.performTraversals(ViewRoot.java:845)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method) Caused by: android.content.res.Resources$NotFoundException: Resource is not a ColorStateList (color or path): TypedValue{t=0x1/d=0x7f0d014c a=3 r=0x7f0d014c}
at android.content.res.Resources.loadColorStateList(Resources.java:1804)
at android.content.res.TypedArray.getColorStateList(TypedArray.java:342)
at android.widget.TextView.(TextView.java:445)
at org.holoeverywhere.widget.TextView.(SourceFile:133)
at org.holoeverywhere.widget.TextView.(SourceFile:129)
... 29 more android.content.res.Resources$NotFoundException: Resource is not a ColorStateList (color or path): TypedValue{t=0x1/d=0x7f0d014c a=3 r=0x7f0d014c}
at android.content.res.Resources.loadColorStateList(Resources.java:1804)
at android.content.res.TypedArray.getColorStateList(TypedArray.java:342)
at android.widget.TextView.(TextView.java:445)
at org.holoeverywhere.widget.TextView.(SourceFile:133)
at org.holoeverywhere.widget.TextView.(SourceFile:129)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
at org.holoeverywhere.LayoutInflater._createView(SourceFile:358)
at org.holoeverywhere.LayoutInflater.onCreateView(SourceFile:594)
at org.holoeverywhere.LayoutInflater.createViewFromTag(SourceFile:444)
at org.holoeverywhere.LayoutInflater.rInflate(SourceFile:731)
at org.holoeverywhere.LayoutInflater.rInflate(SourceFile:734)
at org.holoeverywhere.LayoutInflater.inflate(SourceFile:538)
at org.holoeverywhere.LayoutInflater.inflate(SourceFile:488)
at com.android.internal.view.menu.MenuItemImpl.createItemView(MenuItemImpl.java:592)
at com.android.internal.view.menu.MenuItemImpl.getItemView(MenuItemImpl.java:577)
at com.android.internal.view.menu.MenuBuilder$MenuAdapter.getView(MenuBuilder.java:1173)
at android.widget.AbsListView.obtainView(AbsListView.java:1592)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1251)
at android.widget.ListView.onMeasure(ListView.java:1162)
at android.view.View.measure(View.java:8313)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
at android.view.View.measure(View.java:8313)
at android.view.ViewRoot.performTraversals(ViewRoot.java:845)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)

这是整个theme.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="CustomWindowTitleText" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
         <item name="android:textColor">@color/primary_text_yellow</item>
         <item name="android:textStyle">bold|italic</item>
    </style>

    <style name="CustomWindowTitleText.ActionBar">
        <item name="android:textSize">@dimen/textsize_mid</item>
    </style>

    <style name="CustomWindowSubTitleText" parent="TextAppearance.Sherlock.Widget.ActionBar.Subtitle">
    </style>


    <!-- Changes the background color of the title bar -->
    <style name="CustomWindowTitleBackground">
         <item name="android:background">@drawable/background_window_title</item>
    </style>

    <!-- Set the theme for the window title -->
    <!-- NOTE: setting android:textAppearance to style defined above -->
    <style name="CustomWindowTitle">
        <item name="android:singleLine">true</item>
        <item name="android:shadowColor">#BB000000</item>
        <item name="android:shadowRadius">2.75</item>
        <item name="android:textAppearance">@style/CustomWindowTitleText</item>
        <item name="android:paddingLeft">40dp</item>
    </style>

    <!--
        http://actionbarsherlock.com/theming.html
        Due to limitations in Android's theming system any theme customizations must be declared in two attributes.
        The normal android-prefixed attributes apply the theme to the native action bar and the unprefixed attributes are for the custom implementation.
    -->
    <style name="CustomActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse"> <!--parent="@android:style/Widget.Holo.ActionBar"-->
        <item name="android:background">@drawable/gradient_lightpurple_darkpurple_off</item> <!-- Use background that has color but not icon. -->
        <item name="android:backgroundSplit">@drawable/gradient_lightpurple_darkpurple_off</item> <!-- Use background that has color but not icon. -->
        <item name="android:titleTextStyle">@style/CustomWindowTitleText.ActionBar</item>
        <item name="android:subtitleTextStyle">@style/CustomWindowSubTitleText</item>

        <item name="background">@drawable/gradient_lightpurple_darkpurple_off</item> <!-- Use background that has color but not icon. -->
        <item name="backgroundSplit">@drawable/gradient_lightpurple_darkpurple_off</item> <!-- Use background that has color but not icon. -->
        <item name="titleTextStyle">@style/CustomWindowTitleText.ActionBar</item>
        <item name="subtitleTextStyle">@style/CustomWindowSubTitleText</item>
    </style>

     <!-- Override properties in the default theme -->
     <!-- NOTE: If you change the windowTitleTextSize you must explicitly the windowTitleSize property, the title bar will not re-size automatically, text will be clipped -->
    <style name="JumbleeTheme" parent="Holo.Theme"> <!-- extends Theme.Sherlock -->
        <item name="android:windowTitleStyle">@style/CustomWindowTitle</item>
        <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
        <item name="android:windowBackground">@drawable/gradient_off_darkpurple_off</item>
        <item name="android:windowActionBar">true</item>
        <item name="android:actionBarStyle">@style/CustomActionBar</item>
        <item name="actionBarStyle">@style/CustomActionBar</item>
    </style>

    <style name="JumbleeTheme.GameScreen">
        <item name="android:windowBackground">@color/black</item>
    </style>


    <!-- Facebook Theme -->

    <style name="CustomWindowTitleText.ActionBar.Facebook">
        <item name="android:textColor">@color/primary_text_white</item>
    </style>
    <!--
        http://actionbarsherlock.com/theming.html
        Due to limitations in Android's theming system any theme customizations must be declared in two attributes.
        The normal android-prefixed attributes apply the theme to the native action bar and the unprefixed attributes are for the custom implementation.
    -->
    <style name="CustomActionBar.Facebook">
        <item name="android:background">@drawable/background_window_title_facebook</item> <!-- Use background that has color but not icon. -->
        <item name="android:backgroundSplit">@drawable/background_window_title_facebook</item> <!-- Use background that has color but not icon. -->
        <item name="android:titleTextStyle">@style/CustomWindowTitleText.ActionBar.Facebook</item>

        <item name="background">@drawable/background_window_title_facebook</item> <!-- Use background that has color but not icon. -->
        <item name="backgroundSplit">@drawable/background_window_title_facebook</item> <!-- Use background that has color but not icon. -->
        <item name="titleTextStyle">@style/CustomWindowTitleText.ActionBar.Facebook</item>
    </style>

    <!-- Facebook Sender Activity -->
    <style name="FacebookSenderTheme" parent="Holo.Theme.Light">
        <item name="android:actionBarStyle">@style/CustomActionBar.Facebook</item>
        <item name="actionBarStyle">@style/CustomActionBar.Facebook</item>
    </style>
</resources>

是primary_text_yellow的来源

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:color="@color/text_light_disabled" />
    <item android:color="@color/app_yellow"/>
</selector>

4 个答案:

答案 0 :(得分:23)

我很确定我遇到过同样的问题。我愿意打赌它与操作系统无关。它是由Android中的那个东西引起的,你可以根据你的主题或其他条件用一个Drawable代替另一个Caused by: android.content.res.Resources$NotFoundException: Resource is not a ColorStateList (color or path): TypedValue{t=0x1/d=0x7f0d014c a=3 r=0x7f0d014c}。事实证明,Android资源编译器没有(总是?永远?)检查别名后面是否有“真实”。

以下是调试方法......

从这一行开始,它告诉你一些特定的缺失 - ID:

bin/R.text

现在转到0x7f0d014c,然后搜索提供的ID代码:int attr actionModeCloseDrawable 0x7f0d014c。 应该是这样的: actionModeCloseDrawable

现在查找名称actionModeCloseDrawable或工作区中的名称。我相信你会发现它是不存在的资源的别名。即,有一个配置(版本号,屏幕大小等),attr根本不会映射到任何东西。

需要注意的重要事项: 确保检查找到abc_myfragment.xml或其他任何地方的所有地点。它可能看起来像是在“无关紧要”的地方,但这是遇到的第二个问题:在我将问题“修复”到一个abc_myfragment_large.xml之后,我实际上必须在{{1}修复它根据我碰巧运行它的设备,Android自动调用了不同于代码中指定的xml文件。

堆栈跟踪的顶行应该可以帮助您验证您是否正在寻找合适的位置: android.view.InflateException: Binary XML file line #45: Error inflating class

这告诉你某个XML文件的某个部分中引用了缺少的ColorStateList,而那个麻烦的部分从第45行开始 (即开角支架 - “&lt;” - 开始该部分的位置。)

PS我所说的别名就是其中之一:

<attr name="abc_my_home_button" format="reference" />

在两个不同的主题中分别进一步定义:

在themes_light.xml文件中

<item name="afc_button_home">@drawable/afc_button_home_light</item>

文件themes_dark.xml

中的

<item name="afc_button_home">@drawable/afc_button_home_dark</item>

当您将最终定义留在其中一个主题文件中时,会出现问题。

修改

下一步:调查CustomActionBar的依赖关系。我不是风格方面的专家,所以我假设还有9个可能的位置,Android可能会看到它无法找到的ColorStateList的引用:CustomActionBar的父级({ {1}}),以及它包含的8个项目中的每个项目。注释掉这8个项目并删除父项,然后在麻烦的配置中重新运行您的应用程序。检查运行时错误是否消失,或者更可能的是,更改(例如,行号(和id)从#45更改为指示Widget.Sherlock.Light.ActionBar.Solid.Inverse,而不是调用许多相同的资源。然后逐个撤消更改,直到错误更改回原来的状态。这将进一步本地化问题。尝试修复后,请慢慢移动,因为如果您确实发现问题(例如,作为不存在的引用),则可能会在8个项目中的多个项目中进行复制。因此逐一取消注释。

答案 1 :(得分:6)

这绝对是三星Galaxy系列设备的几个成员中的一个错误。 我设法在Galaxy Pocket上复制它,但无法在模拟器上复制它,这是一个小型ldpi Gingerbread的AVD。

重现需要一段时间。当有超过6个菜单项时发生,因此按下硬件菜单按钮会显示5个项目以及“更多”溢出选项。点击“更多”会导致崩溃。

将主题修剪为以下内容仍会导致错误。

<style name="CustomActionBar"> 
   <!-- No styles -->
</style>

<style name="JumbleeTheme" parent="Holo.Theme">
    <item name="android:actionBarStyle">@style/CustomActionBar</item>
    <item name="actionBarStyle">@style/CustomActionBar</item>
</style>

但是将主题修剪为以下内容会使错误消失。

<style name="CustomActionBar"> 
   <!-- No styles -->
</style>

<style name="JumbleeTheme" parent="Holo.Theme">
    <item name="actionBarStyle">@style/CustomActionBar</item>
</style>

因此,出于某种原因,Galaxy设备正在查看“android:actionBarStyle”,即使它们不应该存在并且它们将它们置于非常奇怪的状态。

我采用的解决方案是创建一个values-v11资源文件夹,其中我的theme.xml引用了“android:actionBarStyle”和所有其他Honeycomb + ActionBar属性,并且在我的values \ theme.xml中仅使用ABS属性(例如actionBarStyle / actionBarSize)。

答案 2 :(得分:2)

重新创建刚刚从另一个项目复制的每个资源文件。 Android无法识别资源文件。创建新资源文件,并将旧代码中的代码复制并粘贴到新文件中。应该识别新的资源文件,你的颜色也是

答案 3 :(得分:1)

解决这个问题的一个快速而粗糙的解决方案就是在项目文件夹中使用二进制代码。这将给出引用该值的变量的名称。例如在我的情况下,它有点像这样 -

myviewpager/R.java:        public static final int accent=0x7f0c0000;

之后,只需用项目中定义的硬编码值替换项目中该变量(重音符号)的所有引用,在我的例子中它是#009688。这解决了我的问题。