Problem:
My application works fine on most devices, but crashes on HTC Desire HD , (Android 2.2.1). ( Edit: Error in 2.3.3)
The exception class is android.content.res.Resources$NotFoundException .
Source Method - Resources.loadColorStateList()
detail:
I install textColor using Themes. I declare a textColor in a TextView in an XML layout file ...
<TextView android:id="@+id/accountWarning" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/accountWarning" android:textSize="20sp" android:layout_marginTop="10dp" android:padding="10dp" android:textColor="?textColor"/>
and declare that textColor for each theme should be in the resource theme file ...
<style name="Theme.TxtoolsDark" parent="Theme"> <item name="textColor">#FFFFFF</item> <item name="autoCompleteTextViewTextColor">#000</item> </style> <style name="Theme.TxtoolsLight" parent="Theme" > <item name="textColor">#000</item> <item name="autoCompleteTextViewTextColor">#000</item> </style>
If I just transcode textColor into my xml file, it works fine, so it seems like it doesn’t understand that '?textColor' should make it look at my themes.xml file. Again, this works great on other devices I've tested on, but doesn't work on HTC Desire HD.
Error:
The corresponding stack trace bits ...
android.view.InflateException: Binary XML file line #10: Error inflating class <unknown>
and
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-hdpi/scrollbar_handle_vertical.9.png from drawable resource ID #0x0: .xml extension required at android.content.res.Resources.loadColorStateList(Resources.java:1842) at android.content.res.TypedArray.getColorStateList(TypedArray.java:342) at android.widget.TextView.<init>(TextView.java:665)
Edit: Eclipse 3.5.2 tells me "Unable to resolve color value"? textColor "in the" textColor "attribute on the Graphic Layout tab of my layout.xml. However, I can still compile and create, and it still works on all devices other than HTC Desire HD. The full code is in bottom of this question.
Edit: July 1, 2011
I noticed that I have two separate stack traces (although there is only one line near the end that changes, I think) ...
java.lang.RuntimeException: Unable to resume activity {uk.co.txttools.mobile.android.txttoolsmobile/uk.co.txttools.mobile.android.txttoolsmobile.pages.home.HomeTabs}: java.lang.RuntimeException: Unable to resume activity {uk.co.txttools.mobile.android.txttoolsmobile/uk.co.txttools.mobile.android.txttoolsmobile.pages.home.StandardHome}: android.view.InflateException: Binary XML file line #10: Error inflating class <unknown> at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3399) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3420) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864) at android.app.ActivityThread.access$2300(ActivityThread.java:136) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2179) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:143) at android.app.ActivityThread.main(ActivityThread.java:5073) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:521) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.RuntimeException: Unable to resume activity {uk.co.txttools.mobile.android.txttoolsmobile/uk.co.txttools.mobile.android.txttoolsmobile.pages.home.StandardHome}: android.view.InflateException: Binary XML file line #10: Error inflating class <unknown> at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3399) at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:170) at android.app.LocalActivityManager.dispatchResume(LocalActivityManager.java:521) at android.app.ActivityGroup.onResume(ActivityGroup.java:58) at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1260) at android.app.Activity.performResume(Activity.java:4011) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3389) ... 12 more Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class <unknown> at android.view.LayoutInflater.createView(LayoutInflater.java:513) at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563) at android.view.LayoutInflater.rInflate(LayoutInflater.java:618) at android.view.LayoutInflater.rInflate(LayoutInflater.java:621) at android.view.LayoutInflater.inflate(LayoutInflater.java:407) at android.view.LayoutInflater.inflate(LayoutInflater.java:320) at android.view.LayoutInflater.inflate(LayoutInflater.java:276) at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:217) at android.app.Activity.setContentView(Activity.java:1701) at uk.co.txttools.mobile.android.txttoolsmobile.pages.home.Home.createHomePage(Home.java:88) at uk.co.txttools.mobile.android.txttoolsmobile.pages.home.StandardHome.createHomePage(StandardHome.java:74) at uk.co.txttools.mobile.android.txttoolsmobile.pages.home.Home.onResume(Home.java:291) at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1260) at android.app.Activity.performResume(Activity.java:4011) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3389) ... 18 more Caused by: java.lang.reflect.InvocationTargetException at android.widget.TextView.<init>(TextView.java:355) at java.lang.reflect.Constructor.constructNative(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:446) at android.view.LayoutInflater.createView(LayoutInflater.java:500) ... 33 more Caused by: android.content.res.Resources$NotFoundException: File res/drawable-hdpi/scrollbar_handle_vertical.9.png from drawable resource ID #0x0: .xml extension required at android.content.res.Resources.loadColorStateList(Resources.java:1842) at android.content.res.TypedArray.getColorStateList(TypedArray.java:342) at android.widget.TextView.<init>(TextView.java:665) ... 37 more
and
java.lang.RuntimeException: Unable to resume activity {uk.co.txttools.mobile.android.txttoolsmobile/uk.co.txttools.mobile.android.txttoolsmobile.pages.home.HomeTabs}: java.lang.RuntimeException: Unable to resume activity {uk.co.txttools.mobile.android.txttoolsmobile/uk.co.txttools.mobile.android.txttoolsmobile.pages.home.StandardHome}: android.view.InflateException: Binary XML file line
Edit: July 4th - Full Code
themes.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="Theme" parent="android:Theme"> </style> <style name="Theme.TxtoolsDark" parent="Theme"> <item name="textColor">#FFFFFF</item> <item name="autoCompleteTextViewTextColor">#000</item> </style> <style name="Theme.TxtoolsLight" parent="Theme" > <item name="textColor">#000</item> <item name="autoCompleteTextViewTextColor">#000</item> </style> </resources>
attrs.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <attr name="autoCompleteTextViewTextColor" format="reference|color" /> <attr name="textColor" format="reference|color" /> </resources>
myLayoutFile.xml
<?xml version="1.0" encoding="utf-8"?> <ScrollView android:id="@+id/ScrollView01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbars="vertical" android:scrollbarAlwaysDrawVerticalTrack="true"> <TextView android:id="@+id/accountWarning" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/accountWarning" android:textSize="20sp" android:layout_marginTop="10dp" android:padding="10dp" android:textColor="?textColor"/> <TextView android:id="@+id/haveAccountQuestion" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/haveAccountQuestion" android:textSize="20sp" android:layout_gravity="center_horizontal" android:padding="10dp" android:textColor="?textColor"/> <Button android:id="@+id/yes" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:width="80dp" android:text="@string/yesHappy" android:textSize="15sp" android:layout_gravity="center_horizontal"/> <Button android:id="@+id/no" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:width="80dp" android:text="@string/noSad" android:textSize="15sp" android:layout_gravity="center_horizontal" android:layout_marginTop="10dp"/> <ListView android:id="@android:id/list" android:layout_width="wrap_content" android:layout_height="wrap_content" android:cacheColorHint="#00000000"/> </LinearLayout> </ScrollView>
Edit: July 5, 2011 I found that if I use “android: textColorPrimary” and not “textColor”, the error no longer occurs on HTC Desire HD, but the text color will always remain the default value for textColor. On all devices, it works fine as expected.
Edit: July 6, 2011 Early morning In principle, HTC Desire HD seems to ignore any values set using ??. Despite half the fix described in my last change, I get errors later in my application on pages that use styles.
Editing: July 6, 2011 Late Evening . I have half the problem resolved by roughly setting the color of the text in Java (depending on the topic). However, this still does not work for my text in my ListView, which uses a "style". However, I have now discovered that the rest of my program works fine, despite using "? TextColor"! This means that only the initial screen does not work, which indicates that HTC Desire HD does not create the necessary themes or styles early enough to decrypt “textColor”! (or something like that!) This could be important information! Can I swap my code to make it work?