我一直收到以下错误
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;
}
}
为什么我不断获得越界异常的任何想法?