Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Preferences error
    primarykey
    data
    text
    <p>In my app, I am trying to set up preferences that allows you to change the background image of a layout from a ton of choices in a ListPreference. My preferences xml: </p> <pre><code>&lt;PreferenceCategory android:title="Favorite Team"&gt; &lt;ListPreference android:title="Favorite Team" android:summary="@string/prefs_pick_fav_team" android:key="keyFavTeam" android:entries="@array/teams" android:entryValues="@array/teams_values" android:defaultValue="0" /&gt; &lt;/PreferenceCategory&gt; </code></pre> <p>The PreferencesActivity, which is also in the Manifest:</p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.prefs); } </code></pre> <p>And then this is the code from my onCreate of the screen I want the background changed:</p> <pre><code>SharedPreferences SP = PreferenceManager .getDefaultSharedPreferences(getBaseContext()); String strFavTeam = SP.getString("keyFavTeam", "0"); LinearLayout linearLayout = (LinearLayout) this.findViewById(R.id.main_screen); if(strFavTeam.equals("0")){ linearLayout.setBackgroundResource(R.drawable.first_screen); } if(strFavTeam.equals("73")){ linearLayout.setBackgroundResource(R.drawable.tennessee_screen); } if(strFavTeam.equals("67")){ linearLayout.setBackgroundResource(R.drawable.georgia_screen); } </code></pre> <p>My problem is that I get a force close when I choose Tennessee (which has the value 73) from the ListPreference. </p> <p>This is the stack trace from the LogCat:</p> <pre><code>07-14 23:43:35.535: ERROR/AndroidRuntime(5581): FATAL EXCEPTION: main 07-14 23:43:35.535: ERROR/AndroidRuntime(5581): java.lang.ArrayIndexOutOfBoundsException 07-14 23:43:35.535: ERROR/AndroidRuntime(5581): at android.preference.ListPreference.onDialogClosed(ListPreference.java:218) 07-14 23:43:35.535: ERROR/AndroidRuntime(5581): at android.preference.DialogPreference.onDismiss(DialogPreference.java:383) 07-14 23:43:35.535: ERROR/AndroidRuntime(5581): at android.app.Dialog$ListenersHandler.handleMessage(Dialog.java:1047) 07-14 23:43:35.535: ERROR/AndroidRuntime(5581): at android.os.Handler.dispatchMessage(Handler.java:99) 07-14 23:43:35.535: ERROR/AndroidRuntime(5581): at android.os.Looper.loop(Looper.java:130) 07-14 23:43:35.535: ERROR/AndroidRuntime(5581): at android.app.ActivityThread.main(ActivityThread.java:3683) 07-14 23:43:35.535: ERROR/AndroidRuntime(5581): at java.lang.reflect.Method.invokeNative(Native Method) 07-14 23:43:35.535: ERROR/AndroidRuntime(5581): at java.lang.reflect.Method.invoke(Method.java:507) 07-14 23:43:35.535: ERROR/AndroidRuntime(5581): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 07-14 23:43:35.535: ERROR/AndroidRuntime(5581): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 07-14 23:43:35.535: ERROR/AndroidRuntime(5581): at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>Can someone tell me what I need to do to prevent this and move on with changing the background?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload