我只是想顯示我的數(shù)組中的列表arrays.xml。當我嘗試在模擬器中運行它時,我收到了強制關(guān)閉消息。如果我在Java文件中定義數(shù)組String[] testArray = new String[] {"one","two","three","etc"};它有效,但是當我使用String[] testArray = getResources().getStringArray(R.array.testArray);它不起作用。這是我的Java文件:package com.xtensivearts.episode.seven;import android.app.ListActivity;import android.os.Bundle;import android.widget.ArrayAdapter;public class Episode7 extends ListActivity { String[] testArray = getResources().getStringArray(R.array.testArray); /** Called when the activity is first created. */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create an ArrayAdapter that will contain all list items ArrayAdapter<String> adapter; /* Assign the name array to that adapter and also choose a simple layout for the list items */ adapter = new ArrayAdapter<String>( this, android.R.layout.simple_list_item_1, testArray); // Assign the adapter to this ListActivity setListAdapter(adapter); }}這是我的arrays.xml檔案<?xml version="1.0" encoding="utf-8"?> <resources> <array name="testArray"> <item>first</item> <item>second</item> <item>third</item> <item>fourth</item> <item>fifth</item> </array></resources>
3 回答

斯蒂芬大帝
TA貢獻1827條經(jīng)驗 獲得超8個贊
您的XML并不十分清楚,但是如果您將數(shù)字設為數(shù)字和/或在其定義中添加空格,則數(shù)組XML可能會導致強制關(guān)閉。
確保將它們定義為沒有前導或尾隨空白
添加回答
舉報
0/150
提交
取消