Cursor Index Out of Bounds Exception

前端 未结 2 1575
Happy的楠姐
Happy的楠姐 2021-01-07 01:44

In attempting to execute a query on my database, I get this exception. However, the documentation states that the method SQLiteDatabase.query(...) returns, \"A

相关标签:
2条回答
  • 2021-01-07 02:10

    After query you need to call next() or moveToFirst(). Cursors are lazy loaded, after calling these methods cursor is loaded into memory. You can decide when to do it.

    0 讨论(0)
  • 2021-01-07 02:12

    to iterate trough all rows:

    Cursor c = db.query(TABLENAME, null, null, null, null, null, null); 
    while(c.moveToNext()) {
          int id = c.getInt(c.getColumnIndex("_ID")); 
    }
    

    or you can use other cursor functions, for example moveToPosition() to access row specified by id

    more info: http://developer.android.com/reference/android/database/Cursor.html

    0 讨论(0)
提交回复
热议问题