Im playing with sql in android and found this issue:
Im reading data from my database:
SQLiteDatabase db = this.getReadableDatabase();
cursor = db.rawQuery("SELECT * FROM " + TABLE_SINGLE_APPS + " WHERE " + COLUMN_SINGLE_PACKAGE + "=?"
, new String[]{packageName});
SingleAppModel singleAppModel = new SingleAppModel();
and when I try to get cursor.getInt(3) over here:
try {
if (cursor.getCount() != 0) {
if (cursor.moveToFirst()) {
singleAppModel.setId(cursor.getInt(0));
singleAppModel.setAppName(cursor.getString(1));
singleAppModel.setPackageName(cursor.getString(2));
singleAppModel.setState(cursor.getInt(3) == 1);
}
}
} catch (Exception e) {
e.printStackTrace();
}
cursor.close();
db.close();
It returns error:
android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0`
Weird is that if I delete line where Im calling cursor.getInt(3), it works. Colum with that value exists and Im sure its of type INTEGER.
Also the value of cursor.getColumnCount() is 4 and value of cursor.getCount() is 1 ... so there are definetly some data...
Any advice?
Thankyou.