在我的应用程序中,我正在尝试从数据库中的表中读取数据,该表的创建方式如下:
public DBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String createDreamTable = String.format("CREATE TABLE IF NOT EXISTS %s" +
"( %s INTEGER PRIMARY KEY AUTOINCREMENT, " +
"%s VARCHAR, " +
"%s TEXT);",
DreamContract.Dream.DREAM_TABLE_NAME,
DreamContract.Dream._ID,
DreamContract.Dream.COLUMN_NAME_DREAM_TITLE,
DreamContract.Dream.COLUMN_NAME_DREAM_CONTENT);
Log.d("avirankatz", createDreamTable);
db.execSQL(createDreamTable);
}
当我尝试使用GetDreamTitles
从数据库获取数据时,如下所示,我得到java.lang.IllegalArgumentException: column '_id' does not exist
public Cursor getDreamTitles() {
return getReadableDatabase().rawQuery(String.format("SELECT %s FROM %s", DreamContract.Dream.COLUMN_NAME_DREAM_TITLE, DreamContract.Dream.DREAM_TABLE_NAME), null);
}
修改
DreamContract.Dream
:
public static abstract class Dream implements BaseColumns {
public static final String DREAM_TABLE_NAME = "dreamDiary";
public static final String COLUMN_NAME_DREAM_TITLE = "title";
public static final String COLUMN_NAME_DREAM_CONTENT = "dreamContent";
}
答案 0 :(得分:2)
在您的查询中添加主键TypeError: undefined is not an object (evaluating 'newWindow.focus')
,如下所示
_id