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

4

12

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>
Oates answered 3/9, 2013 at 23:2 Comment(2)
looks like you have the default text color set to something that is probably a drawable or set to null or something. In your activity theme, what is the TextViewStyle and associated TextAppearance definition?Fairing
Hi Greg, added details above. The only time I override TextAppearance is to set it to @style/CustomWindowTitleText.Oates
O
6

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

Oates answered 16/9, 2013 at 10:46 Comment(2)
First the question just for info: For which API version did you compile? And a remark: Galaxy Pocket has a 240x320 screen. This puts it in a range of low dpi devices. Action Bar Sherlock has an empty drawable-ldpi folder, holoeverywhere does not even have one. But devices handle this diferently. I have a situation where app works on Android 2.2 and fails on 4.3. Is it possible to check for this posibility (missing graphics in drawable-ldpi) so we can narrow down the issue and perhaps create an issue on Github?Pigfish
I would have compiled for 4.3. Well aware that the Pocket is small-ldpi device, but it is also Gingerbread. Gingerbread devices should NOT be looking at the "android:actionBarStyle" attribute as ActionBar was only introduced in Honeycomb. Removing this attrribute in pre Gingerbread devices still allows ABS to work as it uses the "actionBarStyle" attribute.Oates
A
22

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.

Alerion answered 9/9, 2013 at 7:17 Comment(7)
Hi Merk, that value maps to the R$style attribute CustomActionBar = 0x7f0d014c; Which you can see is defined above, is defined for all device configs, and is only referenced in the that theme.xml displayed above.Oates
Thanks Merck. This wasn't the solution, but you gave me enough ideas and put enough effort into your answer that I'm awarding you the bounty. I'll list the solution in a minute.Oates
What would it mean if ID is not to be found in R.txt? E.g. in above case there would be no 0x7f0d014c?Pigfish
@Pigfish it could be that the resourceId refers to a resource in either a library you have imported or one of the AOSP resources.Oates
@Oates So it is. It is defined as a theme atribute in a library (holoeverywhere) it is also set to a valid selector and yet it causes this exception. I want to post a specific question with xml code excerpts but stack overflow site is experiencing problems so I cannot post question. I wish admins would actually do something.Pigfish
in my case, Android Studio added a resource value in v21 folder, so, android pre 21 can´t load the resource (because doesn't exists for those apis) just for 21 or highter, following this steps i located the missing resource and re located it to a generic folder for all apis.Crime
My problem was with inflating the <android.support.v4.view.PagerTabStrip. Crashed only in API 19. Followed above process and found PrimaryColor was the problem. Removed the line from styles and hey presto!Playful
O
6

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

Oates answered 16/9, 2013 at 10:46 Comment(2)
First the question just for info: For which API version did you compile? And a remark: Galaxy Pocket has a 240x320 screen. This puts it in a range of low dpi devices. Action Bar Sherlock has an empty drawable-ldpi folder, holoeverywhere does not even have one. But devices handle this diferently. I have a situation where app works on Android 2.2 and fails on 4.3. Is it possible to check for this posibility (missing graphics in drawable-ldpi) so we can narrow down the issue and perhaps create an issue on Github?Pigfish
I would have compiled for 4.3. Well aware that the Pocket is small-ldpi device, but it is also Gingerbread. Gingerbread devices should NOT be looking at the "android:actionBarStyle" attribute as ActionBar was only introduced in Honeycomb. Removing this attrribute in pre Gingerbread devices still allows ABS to work as it uses the "actionBarStyle" attribute.Oates
B
2

Recreate every resource file you just copied from another project. Android won't recognize the resource file. create new resource file and copy and paste the code from the old one into the new one. The new resource file should be recognized and your colors will be too

Bathroom answered 14/5, 2015 at 2:13 Comment(0)
S
1

One fast and crude solution to this problem is to just grep the binary code in your project folder. This will give the name of the variable which refers to that value. For example in my case it was some thing like this -

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

After that just replace all the references for that variable(accent) in your project by the hardcoded value defined corresponding to it some xml file in your project , in my case it was #009688. This solved the problem in my case.

Shaeshaef answered 15/6, 2015 at 20:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.