Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Custom Background Causing Number Format Exception with List Adapter

So I'm getting some strange behavior with one of my Android apps. I have two apps, both with the same custom background image, and one works just fine. The other, however, does not want to cooperate.

I add a custom theme in my AndroidManifest.xml via the following:

<application
    ...
    android:theme="@style/MyTheme" >

I change my styles.xml (the entire file) to the following:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
  <style name="MyTheme" parent="android:Theme.Holo">
    <item name="android:background">@drawable/dummy_background_image</item>
  </style>
</resources>

Again, this works just fine for app #1. But app #2...

When I call this:

    setListAdapter(new ArrayAdapter<Game>(getActivity(),
                                                  android.R.layout.simple_list_item_activated_1,
                                                  android.R.id.text1,
                                                  gameCategories.getCategories()));

It throws:

01-22 21:30:21.439: E/AndroidRuntime(28044): FATAL EXCEPTION: main
01-22 21:30:21.439: E/AndroidRuntime(28044): java.lang.NumberFormatException: Invalid int: "res/drawable/dummy_background_image.png"
01-22 21:30:21.439: E/AndroidRuntime(28044):    at java.lang.Integer.invalidInt(Integer.java:138)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at java.lang.Integer.parse(Integer.java:375)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at java.lang.Integer.parseInt(Integer.java:366)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at com.android.internal.util.XmlUtils.convertValueToInt(XmlUtils.java:122)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at android.content.res.TypedArray.getInt(TypedArray.java:255)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at android.view.animation.Animation.<init>(Animation.java:251)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at android.view.animation.AlphaAnimation.<init>(AlphaAnimation.java:40)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:117)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:92)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at android.view.animation.AnimationUtils.loadAnimation(AnimationUtils.java:73)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at android.support.v4.app.ListFragment.setListShown(ListFragment.java:290)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at android.support.v4.app.ListFragment.setListAdapter(ListFragment.java:186)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at com.example.legacy.GameListFragment.updateListAdapter(GameListFragment.java:107)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at com.example.legacy.GameListActivity.updateListAdapter(GameListActivity.java:158)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at com.example.legacy.databaseAccess.DatabaseAccessTask.onPostExecute(DatabaseAccessTask.java:57)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at com.example.legacy.databaseAccess.DatabaseAccessTask.onPostExecute(DatabaseAccessTask.java:1)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at android.os.AsyncTask.finish(AsyncTask.java:631)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at android.os.AsyncTask.access$600(AsyncTask.java:177)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at android.os.Looper.loop(Looper.java:137)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at android.app.ActivityThread.main(ActivityThread.java:5455)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at java.lang.reflect.Method.invokeNative(Native Method)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at java.lang.reflect.Method.invoke(Method.java:525)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
01-22 21:30:21.439: E/AndroidRuntime(28044):    at dalvik.system.NativeStart.main(Native Method)

When I go through debug mode, the app does display the app briefly (before it gets to the list adapter) so it can at least find the file.

Obviously, I get that it's a string, and casting it to an int is going to fail. But why is this casting it to an int and not getting the corresponding number? Why does it work for app #1 and app #2?

Thanks in advance.

like image 537
JuniorIncanter Avatar asked Feb 23 '26 20:02

JuniorIncanter


1 Answers

The problem is in

  <item name="android:background">@drawable/dummy_background_image</item>

instead, use

  <item name="android:windowBackground">@drawable/dummy_background_image</item>

and it will work

like image 50
martinpelant Avatar answered Feb 25 '26 10:02

martinpelant