任何人都可以看到为什么这不起作用。我正在尝试向表中添加一个简单的行,然后确认它已正确添加。当我尝试查询表时,我的程序崩溃了。看了这么久,我的头很痛。
addNewGame(1);
Cursor cursor2 = db.query(myDBOpenHelper.GAMES_TABLE, new String [] {"MAX("+GAME_COLUMN+") AS GC"}, null, null, null, null, null);
System.err.println("made it this far");
String temp = cursor2.getString(cursor.getColumnIndex("GC")); //crash!!!
System.err.println("didn't get here);
private static void addNewGame(int g) {
ContentValues newValues = new ContentValues();
SQLiteDatabase db = DBOpenHelper.getWritableDatabase();
newValues.put(GAME_COLUMN, g);
newValues.put(CIV_COLUMN, "");
db.insert(myDBOpenHelper.GAMES_TABLE, null, newValues);
}
线程以未捕获的异常退出
此外,这是创建表的代码:
private static final String GAMES_CREATE = "create table " +
GAMES_TABLE + " (" + KEY_ID +
" integer primary key autoincrement, " +
GAME_COLUMN + " text not null, " +
CIV_COLUMN + " text);";
db.execSQL(GAMES_CREATE);