开发者

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"));
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜