我想我已经检查过这个问题的所有帖子,但似乎没有人帮我...
基本的东西 - 尝试使用绑定到我的数据库的游标适配器,但我得到了:
java.lang.IllegalArgumentException: column '_id' does not exist
我的架构已定义该列(虽然我有2个表,两个名称相同 - 这是一个问题?),如下所示:
public static abstract class dbMain implements BaseColumns {
public static final String TABLE_NAME = "mpgMain";
public static final String ENTRY_ID = "_id";
public static final String VEHICLE_NAME = "v_name";
}
public static abstract class dbHistory implements BaseColumns {
public static final String TABLE_NAME = "mpgHistory";
public static final String ENTRY_ID = "_id";
public static final String TRIP_DATE = "date";
}
从其他帖子中,我已将_id放在我的光标中:
String[] projection = {dbMain.ENTRY_ID, dbMain.VEHICLE_NAME};
Cursor mpgCur = mpgDB.query(dbMain.TABLE_NAME, projection, null, null, null, null, null);
...但是我的堆栈跟踪在查询行上给出了相同的错误。如果我从投影中删除ENTRY_ID,同样的错误,但在后面的行实例化适配器:
String[] fromColumns = {dbMain.VEHICLE_NAME};
int[] toViews = {R.id.displayVehicle};
SimpleCursorAdapter vehAdapter = new SimpleCursorAdapter(this,
R.layout.activity_first_screen, mpgCur, fromColumns, toViews, 0); <--- HERE
我还尝试在_id字段之前的CREATE TABLE命令中添加一个空格:
private static final String SQL_CREATE_MAIN_TABLE =
"CREATE TABLE " + dbMain.TABLE_NAME + " ( " +
dbMain.ENTRY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
感激不尽的任何想法......
答案 0 :(得分:0)
如果我没弄错,通过实现BaseColumns,您不必在架构中指定“_id”。只需使用常量_ID(所以,dbMain._ID
和dbHistory._ID
)