2011-04-26 4 views
11

스피너 선택을 기반으로 선택하려는 XML 파일의 값 목록이 있습니다. 어떤 이유로 든 스피너에 배열 문자열을 사용하면 문제가 발생하지 않고 값이 스피너에 채워집니다. 어떤 이유로 든 제 인생을 구하기 위해 두 번째 배열의 값을 얻을 수 없습니다. 오류가없는 동일한 파일에 있습니다. (오류가이 부분을하지 않는 것)XML에서 배열 문자열 리소스를 가져올 수 없습니다.

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

스피너 다르게 채워집니다 :

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
    this, R.array.playerclass_array, android.R.layout.simple_spinner_item); 

내가 점점 오전 오류는 다음과 같습니다

"여기에 내가 그들을 잡으려고 노력하고있는 방법입니다 04:16 21 : 41 : 35.305 : 오류/AndroidRuntime (514) : 원인 : android.content.res.Resources $ NotFoundException : 문자열 배열 리소스 ID # 0x7f050001 "

직접"getResources " 선. 누군가 이런 일이 일어날 수있는 어떤 단서가 있습니까?

편집 : 여기에 XML 파일 난 직후 답을 찾을 때

<?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> 

답변

11

나는 그것을 싫어합니다 (간단)!

어떤 이유인지 Android에서 배열이 포함 된 XML 파일을 제대로 다시 컴파일하지 않아 이름을 변경 한 다음 다시 변경하면 이제 작동합니다. 따라서 필자의 말처럼 Eclipse가 올바르게 컴파일되지 않았기 때문에 XML 파일에서 배열을 수정해야했습니다.

+0

답변으로 표시하여 필터링 할 수 있습니다. –

+0

나는 기다려야한다. 분명히 자신의 질문에 답하는 데 2 ​​일의 시간 제한이있다. 누군가가 같은 문제에 부딪 힐 경우를 대비해서 (질문) 떠날 것입니다. – Organiccat

+0

"바로 대답을 찾으면 나는 싫어!" 같은 일이 적어도 3-4 번 나 일어났습니다 : p –

2

나는 여러 번 비슷한 문제가 발생했습니다. 나는 그것이 프로젝트 | Eclipse의 Clean 옵션을 선택하고 프로젝트를 재구성하면 항상 해결됩니다. 이것은 본질적으로 XML 파일을 편집하여 수행하는 작업입니다. Eclipse가 XML 파일에서 자원을 다시 빌드하도록 강요합니다.

6

ArrayAdapter의 생성자에서 Cast를 수행하거나 ArrayAdapter에서 요소의 유형을 변경하려고합니다.

ArrayAdapter<String> adapter = ArrayAdapter.createFromResource(
this, R.array.playerclass_array, android.R.layout.simple_spinner_item); 
관련 문제