I keep getting the following error
android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
I know I have data in the database because a similar query for all the data (rather than a single entry) pulls out a list successfully
Here is my code for the database helper
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;
}
}
Any ideas why I keep getting the out of bounds exception?
Aucun commentaire:
Enregistrer un commentaire