0
任何人都可以看到为什么这不起作用。我试图向表中添加一个简单的行,然后确认它已正确添加。当我试图查询表时,我的程序崩溃。我的头因久久盯着这个而感到痛苦。SQLite无法验证插入
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);
工作正常!我不明白为什么当我插入记录时我不得不检查空游标,但在这一点上我不在乎。如果我能给你1000000 + 1的话,我会的。非常感谢! – Alex
大多数WelCome亲爱的。 –