【发布时间】:2011-05-28 20:04:14
【问题描述】:
我被 SimpleCursorAdapter 卡住了,我正在调用我的本地 SQLite DB 并将其放入一个游标中,然后将其传递给 SimpleCursorAdapter。
出于同样的原因,Log Cat 一直在下面显示此错误。我不知道发生了什么,我已经为此工作了 6 个小时,我没想到 SimpleCursorAdapter 会这么难理解。
05-28 19:47:27.524: ERROR/AndroidRuntime(9353): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nyneaxis.android.mpg/com.nyneaxis.android.mpg.userInfo}: java.lang.IllegalArgumentException: column '_id' does not exist
setArray();
rec.open();
Cursor c = rec.getAllVeh();
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.userinfo, c, new String[]{c.getString(1)}, new int[]{R.id.nameTxtL});
this.setListAdapter(adapter);
rec.close();
//数据适配器
public Cursor getAllVeh() {
try{
return db.query(database_table, new String[] { key_rowid, vehicle_name,
year, make, model, style, vin, plate, notes }, null, null,
null, null, null);
}finally{
}
}
好的,我已将代码修改为 rawQuery,但我再次收到此错误:
05-28 22:41:48.876: 错误/AndroidRuntime(1359): java.lang.RuntimeException: 无法启动活动 ComponentInfo{com.nyneaxis.android.mpg/com.nyneaxis.android.mpg.userInfo}: android.database.CursorIndexOutOfBoundsException: 请求索引-1,大小为0
private static final String db_sel = "SELECT id as _id, vehicle_name FROM vehicle";
public Cursor getAllVeh() {
try{
return db.rawQuery(db_sel, null);
/*return db.query(database_table, new String[] { key_rowid, vehicle_name,
year, make, model, style, vin, plate, notes }, null, null,
null, null, null);*/
}finally{
}
}
【问题讨论】:
-
好的,'key_rowid' 是什么意思?
-
查看我的答案的编辑,解释使用 rawQuery 为 _id 列设置别名。
-
你在哪里提到表的名称?
标签: android