Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Samsung Galaxy/Holoeverywhere - Resource is not a ColorStateList (color or path)

I'm getting the following crash on the Samsung Galaxy Ace/Y/Pocket/Mini. It runs fine on all other devices. Crashes are only occurring on Android 2.3.5 or 2.3.6

There is no ref to my code in the stacktrace. It seem to come from the menu layout which I haven't customised.

I suspect that it is a fault in the Galaxy OS. But can't confirm.

More importantly, what can I can do avoid or mitigate this error?

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)

Here is the entire 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>

And the source for 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>
like image 789
William Avatar asked Sep 03 '13 23:09

William


2 Answers

I'm pretty sure I've had this same problem. I'm willing to bet it has nothing to do with the OS. It's caused by that thing in Android where you can substitute one Drawable for another depending on your theme or some other condition. It turns out that the Android resource compiler doesn't (always? ever?) check if there's anything 'real' behind an alias.

Here is how you debug it...

Start with this line, it tells you something specific about what is missing--the ID:

Caused by: android.content.res.Resources$NotFoundException: Resource is not a ColorStateList (color or path): TypedValue{t=0x1/d=0x7f0d014c a=3 r=0x7f0d014c}

Now go to bin/R.text, and search for the ID code that is given: 0x7f0d014c. There should be something like this: int attr actionModeCloseDrawable 0x7f0d014c

Now look for the name actionModeCloseDrawable or whatever it is in your workspace. I believe that you will find that it is an alias for a non-existent resource. i.e., there is a configuration (version number, screen size, etc.) under which that attr does not map to anything at all.

Important things to note: Make sure to check ALL places where you find actionModeCloseDrawable or whatever it is. It might look like it is in a place where it 'doesn't matter' but this was a second problem encountered: after I 'fixed' the issue in one abc_myfragment.xml, I actually had to fix it in abc_myfragment_large.xml -- Android was automatically calling a different xml file than the one specified in code, based on the device I happened to be running it on.

The top line of your stack trace should help you verify that you are looking in the right place: android.view.InflateException: Binary XML file line #45: Error inflating class

This tells you that the missing ColorStateList is being referred to in a section of some XML file somewhere, and that that troublesome section starts on line 45 (i.e., that's where the open angle bracket --"<"-- starting the section is.)

PS What I mean by alias is one of these:

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

which gets separate further definitions in two separate themes:

<item name="afc_button_home">@drawable/afc_button_home_light</item> in the file themes_light.xml

and

<item name="afc_button_home">@drawable/afc_button_home_dark</item> in the file themes_dark.xml

The trouble arises when you leave the final definition out of one of the theme files.

EDIT

Next step: Investigate CustomActionBar's dependencies. I'm not an expert on styles, so I will assume there are 9 possible places remaining where Android might see a reference to a ColorStateList that it can't find: in the parent of CustomActionBar (Widget.Sherlock.Light.ActionBar.Solid.Inverse), and in each of the 8 items it contains. Comment out those 8 items and get rid of the parent, then rerun your app in the troublesome configuration. Check if the runtime error goes away or, more likely, changes (e.g., line number (and id) changes from #45 to indicate CustomActionBar.Facebook instead, where many of the same resources are invoked). Then undo the changes one by one until the error changes back to what it was before. This will further localize the problem. After attempting a fix, move slowly, since it is possible that if you do find the problem (e.g., as a non-existent reference) it is replicated in multiple of the 8 items. So uncomment one by one.

like image 165
Merk Avatar answered Oct 20 '22 09:10

Merk


This is most definitely a bug in several members of the Samsung Galaxy series of devices. I managed to replicate it on a Galaxy Pocket but was unable to replicate it on the emulator for an AVD that was small-ldpi Gingerbread.

It took a while to reproduce. Occurs when there are more than 6 menu items, so that pressing on the hardware menu button shows 5 items plus the "More" overflow option. Clicking on "More" causes the crash.

Trimming the theme down to the following still caused the error.

<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>

But trimming the Theme down to the following makes the error disappear.

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

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

So for some reason the Galaxy devices were looking at "android:actionBarStyle" even though they shouldn't be and it puts them into a very strange state.

The solution that I adopted was to create a values-v11 resource folder where my theme.xml has references to "android:actionBarStyle" and all the other Honeycomb+ ActionBar attributes and in my values\theme.xml to only use the ABS attributes (eg actionBarStyle/actionBarSize).

like image 34
William Avatar answered Oct 20 '22 11:10

William