Column Index not finding a column that definitely exists
try {
Cursor c = db.rawQuery("select time from updateTimes where开发者_如何学编程 type = 'root'", null);
long time = c.getLong(c.getColumnIndex("time"));
} catch (CursorIndexOutOfBoundsException e) {
}
This exception gets thrown, even though the column "time" definitely exists, the the same query returns data as expected when using the sqlite3 client. Any ideas?
The cursor is not at a valid index. You need to move it first:
if (c.moveToNext()) {
time = c.getLong(c.getColumnIndex("time"));
}
精彩评论