ListViewの作成中にエラーが発生しました。エラーは次のとおりです。
01-30 18:42:42.177: E/AndroidRuntime(396): FATAL EXCEPTION: main
01-30 18:42:42.177: E/AndroidRuntime(396): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.databasetest/com.example.databasetest.ViewData}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
01-30 18:42:42.177: E/AndroidRuntime(396): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-30 18:42:42.177: E/AndroidRuntime(396): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-30 18:42:42.177: E/AndroidRuntime(396): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-30 18:42:42.177: E/AndroidRuntime(396): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-30 18:42:42.177: E/AndroidRuntime(396): at android.os.Handler.dispatchMessage(Handler.java:99)
01-30 18:42:42.177: E/AndroidRuntime(396): at android.os.Looper.loop(Looper.java:123)
01-30 18:42:42.177: E/AndroidRuntime(396): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-30 18:42:42.177: E/AndroidRuntime(396): at java.lang.reflect.Method.invokeNative(Native Method)
01-30 18:42:42.177: E/AndroidRuntime(396): at java.lang.reflect.Method.invoke(Method.java:521)
01-30 18:42:42.177: E/AndroidRuntime(396): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-30 18:42:42.177: E/AndroidRuntime(396): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-30 18:42:42.177: E/AndroidRuntime(396): at dalvik.system.NativeStart.main(Native Method)
01-30 18:42:42.177: E/AndroidRuntime(396): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
01-30 18:42:42.177: E/AndroidRuntime(396): at android.app.ListActivity.onContentChanged(ListActivity.java:245)
01-30 18:42:42.177: E/AndroidRuntime(396): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201)
01-30 18:42:42.177: E/AndroidRuntime(396): at android.app.Activity.setContentView(Activity.java:1647)
01-30 18:42:42.177: E/AndroidRuntime(396): at com.example.databasetest.ViewData.onCreate(ViewData.java:19)
01-30 18:42:42.177: E/AndroidRuntime(396): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-30 18:42:42.177: E/AndroidRuntime(396): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-30 18:42:42.177: E/AndroidRuntime(396): ... 11 more
エミュレータがandroid:R.id.listを探している理由はわかりません
これがlistViewを使用するアクティビティの私のコードです
package com.example.databasetest;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
import android.widget.ListView;
public class ViewData extends ListActivity {
private DBHandler dbHelper;
private SimpleCursorAdapter dataAdapter;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_data);
displayListView();
}
private void displayListView() {
Cursor cursor = dbHelper.getData();
String[] columns = new String[] {
DBHandler.COL_NAME,
DBHandler.COL_ADDRESS,
DBHandler.COL_PHONE,
DBHandler.COL_EMAIL
};
int[] to = new int[] {
R.id.name,
R.id.address,
R.id.phone,
R.id.email,
};
dataAdapter = new SimpleCursorAdapter(this, R.layout.country_info,
cursor,
columns,
to,
0);
ListView listView = (ListView) findViewById(R.id.listView1);
// Assign adapter to ListView
listView.setAdapter(dataAdapter);
}
}
これが、listViewview_data.xmlに使用する2つのXMLファイルです。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
そして最後にcountry_info.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="6dip" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Name: "
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:text="Address: "
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:text="Phone: "
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_below="@+id/textView3"
android:text="Email: "
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView3"
android:layout_alignBottom="@+id/textView3"
android:layout_toRightOf="@+id/textView3"
android:text="Test" />
<TextView
android:id="@+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView4"
android:layout_alignBottom="@+id/textView4"
android:layout_alignLeft="@+id/continent"
android:text="Test" />
<TextView
android:id="@+id/phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView3"
android:layout_toRightOf="@+id/textView3"
android:text="Test" />
<TextView
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView2"
android:layout_alignLeft="@+id/name"
android:text="Test" />
</RelativeLayout>
あなたが私を助けてくれることを願っています。前もって感謝します。