Android游标始终返回null

时间:2015-07-14 22:44:15

标签: android sqlite

我一直收到以下错误

android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1

我知道数据库中有数据,因为对所有数据(而不是单个条目)的类似查询会成功提取列表

这是我的数据库帮助程序代码

public class DatabaseHandler extends SQLiteOpenHelper {
    ...

    public Service getMostRecentService() {
    SQLiteDatabase db = this.getReadableDatabase();
    String selectQuery = "SELECT  * FROM " + TABLE_CONTACTS + " ORDER BY " + KEY_ID + " DESC LIMIT 1;";

    Cursor cursor = db.rawQuery(selectQuery, null);

    Service service = new Service();
    if(cursor != null) {
        service = new Service(cursor.getString(1), cursor.getString(2));
    }

    return service;
    }
}

为什么我不断获得越界异常的任何想法?

0 个答案:

没有答案