开发者

Column Index not finding a column that definitely exists

开发者 https://www.devze.com 2023-02-11 12:05 出处:网络
try { Cursor c = db.rawQuery(\"select time from updateTimes where开发者_如何学编程 type = \'root\'\", null);
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

精彩评论

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

关注公众号