我試圖加載從陣列中物品的列表...我得到運行時錯誤如何從Array的產品清單加載到ListView控件
11月2日至22日:22:51.042:E/AndroidRuntime(1460 ):了java.lang.RuntimeException:通過導致您的內容必須有一個ListView其id屬性爲 'android.R.id.list'
我R.java文件
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int ic_launcher=0x7f020000;
public static final int icon=0x7f020001;
}
public static final class id {
public static final int mylist=0x7f050000;
public static final int next=0x7f050005;
public static final int play=0x7f050004;
public static final int prev=0x7f050003;
public static final int seekbar=0x7f050002;
public static final int selectedfile=0x7f050001;
public static final int text1=0x7f050006;
}
public static final class layout {
public static final int audiolist=0x7f030000;
public static final int song_item=0x7f030001;
public static final int songlist=0x7f030002;
}
public static final class string {
public static final int app_name=0x7f040000;
}
}
我的代碼:
@Override
public void onCreate(Bundle icicle) {
try {
super.onCreate(icicle);
setContentView(R.layout.audiolist);
ListView listView = (ListView) findViewById(R.id.mylist);
String[] values = new String[] { "Android", "iPhone", "WindowsMobile"};
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values);
listView.setAdapter(spinnerArrayAdapter);
} catch (NullPointerException e) {
Log.v(getString(R.string.app_name), e.getMessage());
}
}
佈局:audiolist
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/mylist"
android:layout_weight="1.0"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/screen_background_light"
android:padding="10dip">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/selectedfile"
android:text="Not file selected"
android:textColor="@android:color/black"
android:gravity="center_horizontal"
android:singleLine="true"
android:ellipsize="middle"/>
<SeekBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/seekbar"
android:max="100"
android:paddingBottom="10dip"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="@android:drawable/screen_background_light">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/prev"
android:src="@android:drawable/ic_media_previous"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/play"
android:src="@android:drawable/ic_media_play"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/next"
android:src="@android:drawable/ic_media_next"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
你應該看看這個:http://stackoverflow.com/questions/3040374/runtime-exception-listview-whose -id-attribute-is-android-r-id-list – 2012-02-22 16:32:43
不能解決我的問題 – 2012-02-22 17:07:38