2011-02-17 32 views
0
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客戶端時,同樣的查詢將返回數據。有任何想法嗎?列索引找不到肯定存在的列

回答

3

遊標不在有效索引處。您需要先將其移動:

if (c.moveToNext()) { 
    time = c.getLong(c.getColumnIndex("time")); 
} 
+0

非常感謝! – Richard 2011-02-18 09:08:13