try {
Cursor c = db.rawQuery("select time from updateTimes where type = 'root'", null);
long time = c.getLong(c.getColumnIndex("time"));
} catch (CursorIndexOutOfBoundsException e) {
}
抛出此异常,即使列“time”肯定存在,同一查询在使用sqlite3客户端时也会按预期返回数据。有什么想法吗?
答案 0 :(得分:3)
光标不在有效索引处。你需要先移动它:
if (c.moveToNext()) {
time = c.getLong(c.getColumnIndex("time"));
}