我创建了下面列的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