我創建了下面列的SQL數據庫精簡版:的Android SQLite的例外:java.lang.IllegalArgumentException異常:列 '_id' 不存在
static final String dbName="demoDB";
static final String tableName="Employees";
static final String colID="EmployeeID";
然後
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE "+tableName+" ("+colID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+
colName+" TEXT, "+colAge+" Integer);");
}
我想選擇所有在這樣的數據庫中的記錄,並顯示它們在一個gridview:
SQLiteDatabase db=this.getWritableDatabase();
Cursor cur= db.rawQuery("Select "+colName+", "+colAge+" from "+tableName, new String [] {});
String [] from=new String []{DatabaseHelper.colName,DatabaseHelper.colAge};
int [] to=new int [] {R.id.colName,R.id.colAge};
SimpleCursorAdapter sca=new SimpleCursorAdapter(this,R.layout.gridrow,c,from,to);
GridView grid=(GridView)findViewById(R.id.grid);
grid.setAdapter(sca);
但我收到以下ex ception:
java.lang.IllegalArgumentException: column '_id' does not exist.
db表中沒有名爲「_id」列
那麼,什麼是錯,此代碼
感謝
可能重複的[IllegalArgumentException:列_id'不存在調用SimpleCursorAdaptor時](http://stackoverflow.com/questions/3236203/illegalargumentexception-column-id-does-not-exist-when-call- to-simplecursora) – Pentium10 2010-07-14 08:40:55
僅僅因爲其他線程沒有提供答案並不意味着這個不是重複的。 – 2010-07-15 14:35:10