12

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>

3 Answers 3

11

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Mark this as the answer so we can filter it out.
I have to wait, apparently there is a 2 day time limit to answering your own question. I'm leaving it up (the question) in case someone runs into the same issue though.
"I hate it when I find the answer right after!" Same thing has happened to me too atleast 3-4 times :p
6

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

Comments

2

I've run into similar problems several times. I found that using the Project | Clean option in Eclipse and then rebuilding my project always solves them. That's essentially what you're doing by editing the XML file; you're forcing Eclipse to rebuild its resources from the XML file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.