在列表视图中显示我的内容时出现错误。错误说:
05-03 08:00:13.575: E/AndroidRuntime(3341): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.lthomepage/com.android.lthomepage.ListViewDetails}: java.lang.IllegalArgumentException: column '_id' does not exist
05-03 08:00:13.575: E/AndroidRuntime(3341): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-03 08:00:13.575: E/AndroidRuntime(3341): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-03 08:00:13.575: E/AndroidRuntime(3341): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-03 08:00:13.575: E/AndroidRuntime(3341): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-03 08:00:13.575: E/AndroidRuntime(3341): at android.os.Handler.dispatchMessage(Handler.java:99)
05-03 08:00:13.575: E/AndroidRuntime(3341): at android.os.Looper.loop(Looper.java:137)
05-03 08:00:13.575: E/AndroidRuntime(3341): Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
05-03 08:00:13.575: E/AndroidRuntime(3341): at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:303)
05-03 08:00:13.575: E/AndroidRuntime(3341): at android.support.v4.widget.CursorAdapter.init(CursorAdapter.java:174)
05-03 08:00:13.575: E/AndroidRuntime(3341): at android.support.v4.widget.CursorAdapter.<init>(CursorAdapter.java:151)
05-03 08:00:13.575: E/AndroidRuntime(3341): at android.support.v4.widget.ResourceCursorAdapter.<init>(ResourceCursorAdapter.java:93)
05-03 08:00:13.575: E/AndroidRuntime(3341): at android.support.v4.widget.SimpleCursorAdapter.<init>(SimpleCursorAdapter.java:89)
05-03 08:00:13.575: E/AndroidRuntime(3341): at com.android.lthomepage.ListViewDetails.displaylistView(ListViewDetails.java:77)
05-03 08:00:13.575: E/AndroidRuntime(3341): at com.android.lthomepage.ListViewDetails.onCreate(ListViewDetails.java:42)
列表视图代码如下:
Cursor cursor=way.fetchDetails();
String[] columns=new String[] {WayDataBase.KEY_NAME,WayDataBase.KEY_APPNO,WayDataBase.KEY_AMOUNT};
int[] to=new int[] {R.id.name,
R.id.continent,
R.id.region};
adapter=new SimpleCursorAdapter(this, R.layout.country_info, cursor, columns, to, 0);
ListView listview=getListView();
listview.setAdapter(adapter);
数据库代码是:
public Cursor fetchDetails()
{
createAllValuesTable();
Cursor mCursor=db.query(AllValuesTable, new String[] {KEY_NAME,KEY_APPNO,KEY_AMOUNT}, null, null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
我似乎无法弄清楚的问题是什么?我没有任何列作为_id,我没有来自wer 的任何列,它是否显示了这个!请帮忙!谢谢!