0
我在顯示列表視圖時顯示錯誤。 錯誤說:顯示列表視圖時的非法狀態異常
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和我dnt noe從這是顯示這個! 請幫忙!謝謝!
嘿非常感謝!這真的很有幫助!最後問題解決了! – shivani 2013-05-03 10:03:12
謝謝。隨時歡迎 – 2013-05-03 10:13:53