I have a list of values in my XML file which I would like to select based off a spinner selection. For some reason, using an array-string for the spinner works fine, the values are populated into the spinner. For whatever reason, I cannot get the values of the second array to save my life, they are in the same file which has no errors that I can find. Here is the way I am trying to grab them:
String[] some_array = getResources().getStringArray(R.array.playerclassdesc_array);
The spinner is populated differently (no errors doing this part):
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.playerclass_array, android.R.layout.simple_spinner_item);
The error I am getting is:
"04-26 21:41:35.305: ERROR/AndroidRuntime(514): Caused by: android.content.res.Resources$NotFoundException: String array resource ID #0x7f050001"
Which refers directly to the "getResources" line. Does anyone have any clue why this could be happening?
Edit: Here is the xml file (it's simple)
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="class_prompt">Choose a class</string>
<string-array name="playerclass_array">
<item>Assassin</item>
<item>Paladin</item>
<item>Pirate</item>
<item>Hell Mage</item>
<item>Winter Witch</item>
<item>Shadow Walker</item>
<item>Underthief</item>
<item>Red Warrior</item>
<item>Haru Norda</item>
</string-array>
<string-array name="playerclassdesc_array">
<item>This is the Assassin</item>
<item>This is the Paladin</item>
<item>This is the Pirate</item>
<item>This is the Hell Mage</item>
<item>This is the Winter Witch</item>
<item>This is the Shadow Walker</item>
<item>This is the Underthief</item>
<item>This is the Red Warrior</item>
<item>This is the Haru Norda</item>
</string-array>
</resources>
The XML resource files containing localized strings are placed in subfolders of the project's res folder.
XML file saved at res/values/strings.
XML can contain an array with varying numbers of elements. In general, WSDL documents and XML schemas that contain varying numbers of elements do not map efficiently into a single high-level language data structure. CICS® uses container-based mappings or inline mappings to handle varying numbers of elements in XML.
I hate it when I find the answer right after!
For some reason, Android was not properly recompiling the XML file the array was in, so after changing the name, and then changing it back, it now works. So my solution is that I had to make some edits in the XML file the array resided in because it wasn't recompiling correctly despite Eclipse telling me it was.
I try to do a Cast in the constructor of ArrayAdapter, or chage the type of the element in ArrayAdapter.
ArrayAdapter<String> adapter = ArrayAdapter.createFromResource(
this, R.array.playerclass_array, android.R.layout.simple_spinner_item);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With