无法从XML获得数组字符串资源数组、字符串、资源、XML

2023-09-08 09:30:53 作者:若离必弃

我在XML文件中的值,我想选择基于掀起了微调选择的列表。出于某种原因,使用数组,字符串微调做工精细,值被填充到微调。无论出于何种原因,我不能得到第二个数组的值来挽救我的生命,他们在其中有没有错误,我可以找到相同的文件。这里是我试图抓住他们的方式:

 的String [] = some_array getResources()getStringArray(R.array.playerclassdesc_array)。 

微调器不同的填充(没有错误做这个部分):

  ArrayAdapter<&CharSequence的GT;适配器= ArrayAdapter.createFromResource(    对此,R.array.playerclass_array,android.R.layout.simple_spinner_item); 

我得到的错误是:

04-26 21:41:35.305:ERROR / AndroidRuntime(514):$ android.content.res.Resources NotFoundException:致String数组资源ID#0x7f050001

直接指的是getResources行。没有人有任何线索,这可能是为什么发生?

编辑:这是XML文件(很简单)

 <?XML版本=1.0编码=UTF-8&GT?;<资源>    <字符串名称=class_prompt>选择一类< /串>    <字符串数组名=playerclass_array>        <项目>刺客< /项目>        <项目>帕拉丁,LT; /项目>        <项目>&海盗LT; /项目>        <项目>地狱法师< /项目>        <项目>冬季女巫< /项目>        <项目>暗影行者< /项目>        <项目> Underthief< /项目>        <项目>红色战士< /项目>        <项目>春Norda< /项目>    < /字符串数组>    <字符串数组名=playerclassdesc_array>        <项目>这是刺客< /项目>        <项目>这是圣骑士< /项目>        <项目>这是海盗< /项目>        <项目>这是地狱法师< /项目>        <项目>这是冬季女巫< /项目>        <项目>这是暗影行者< /项目>        <项目>这是Underthief< /项目>        <项目>这是红军战士< /项目>        <项目>这是春Norda< /项目>    < /字符串数组>< /资源> 
获取XML字符串 字符串里是XML的内容 里的节点值报错 怎么解决

解决方案

我讨厌它,当我后马上找到了答案!

由于某种原因,Android的是不正确重新编译XML文件中使用数组在,所以改变了名称,然后变回来之后,现在它工作。所以我的解决办法是,我不得不做出了一些XML文件编辑阵列住在,因为它不是Eclipse的,尽管告诉我,这是正确的重新编译。

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>

解决方案

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.