任何人都可以理解为什么这不起作用。我正在尝试向表中添加一个简单的行,然后确认它已正确添加。当我尝试查询表时,我的程序崩溃了。我的头很长时间盯着这个痛苦。
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);
答案 0 :(得分:1)
Just Nothing检查这个。光标是否为空? 试试这段代码吧。
if(cursor2.getcount>0)
{
cursor2.moveTofirst();
String temp = cursor2.getString(cursor.getColumnIndex("GC"));
}
试试这个工作。