我正在尝试将 SimpleCursorAdapter 与 listView 一起使用,但我无法管理它。我厌倦了寻找我找不到的错误。感谢您的帮助。
这是java代码。
public class ButceGetirenListView extends ListActivity {
ListView listLiewGetiren;
TextView textButceGetirList1;
TextView textButceGetirList2;
SimpleCursorAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.butcegetir);
listLiewGetiren=(ListView)findViewById(R.id.list);
String[] from=new String[25];
from[0]="asa";
from[1]="deneme";
int[] to={R.id.textButceGetirList1,R.id.textButceGetirList2};
adapter=new SimpleCursorAdapter(this, R.layout.butcegetirlist, null, from, to, 0);
listLiewGetiren.setAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.butcegiris_xml, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.birinciSayfa:
Intent intent = new Intent(ButceGetirenListView.this, Butcegiris.class);
startActivity(intent); return true;
case R.id.ikinciSayfa:
Intent intent1 = new Intent(ButceGetirenListView.this, Butcehesapla.class);
startActivity(intent1);
return true;
}
return false;
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
}
这是错误日志;
02-03 20:48:10.922: E/AndroidRuntime(441): FATAL EXCEPTION: main
02-03 20:48:10.922: E/AndroidRuntime(441): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.deitel.btc/com.deitel.btc.ButceGetirenListView}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
02-03 20:48:10.922: E/AndroidRuntime(441): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
02-03 20:48:10.922: E/AndroidRuntime(441): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-03 20:48:10.922: E/AndroidRuntime(441): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-03 20:48:10.922: E/AndroidRuntime(441): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-03 20:48:10.922: E/AndroidRuntime(441): at android.os.Handler.dispatchMessage(Handler.java:99)
02-03 20:48:10.922: E/AndroidRuntime(441): at android.os.Looper.loop(Looper.java:123)
02-03 20:48:10.922: E/AndroidRuntime(441): at android.app.ActivityThread.main(ActivityThread.java:4627)
02-03 20:48:10.922: E/AndroidRuntime(441): at java.lang.reflect.Method.invokeNative(Native Method)
02-03 20:48:10.922: E/AndroidRuntime(441): at java.lang.reflect.Method.invoke(Method.java:521)
02-03 20:48:10.922: E/AndroidRuntime(441): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-03 20:48:10.922: E/AndroidRuntime(441): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-03 20:48:10.922: E/AndroidRuntime(441): at dalvik.system.NativeStart.main(Native Method)
02-03 20:48:10.922: E/AndroidRuntime(441): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
02-03 20:48:10.922: E/AndroidRuntime(441): at android.app.ListActivity.onContentChanged(ListActivity.java:245)
02-03 20:48:10.922: E/AndroidRuntime(441): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201)
02-03 20:48:10.922: E/AndroidRuntime(441): at android.app.Activity.setContentView(Activity.java:1647)
02-03 20:48:10.922: E/AndroidRuntime(441): at com.deitel.btc.ButceGetirenListView.onCreate(ButceGetirenListView.java:31)
02-03 20:48:10.922: E/AndroidRuntime(441): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-03 20:48:10.922: E/AndroidRuntime(441): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
02-03 20:48:10.922: E/AndroidRuntime(441): ... 11 more
和butcegetir 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="match_parent"
android:orientation="vertical"
android:gravity="center" >
<TextView
android:id="@+id/listView"
android:text="@string/titleButceGetir"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:gravity="center"
android:padding="15dp" >
</TextView>
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:gravity="center"
android:padding="15dp" >
</ListView>
</LinearLayout>
和 butcegetirlist 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="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/textButceGetirList1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:text="@string/stringButceGetirList1" />
<TextView
android:id="@+id/textButceGetirList2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:text="@string/stringButceGetirList2" />
</LinearLayout>