3

I need help with this error:

Fatal Exception: java.lang.IllegalStateException: Couldn't read row 24929, col 0 from CursorWindow. 
Make sure the Cursor is initialized correctly before accessing data from it

In this code:

SQLiteDatabase db = getReadableDatabase();
Cursor res = db.rawQuery("select id from " + pTable, null);

if (res != null) {
    if (res.getCount() != 0) {
        res.moveToFirst();
        int id;
        while (!res.isAfterLast()) {
            id = res.getInt(res.getColumnIndex("id")); // <-- Error was here
            // ...
            res.moveToNext();
        }
    }
    res.close();
}

This code works sometimes, but when I have many rows (like 25k rows) I get this Exception. Is it a Android restriction?

Could you help me with that? Thanks!

josper04
  • 41
  • 3

1 Answers1

-1
 public ArrayList<Model> Name(){
    ArrayList<Model> ModelList = new ArrayList<>();
    db = getWritableDatabase();
    Cursor c = db.rawQuery(" SELECT * FROM " + pTable,null );
    while (c.moveToNext()){
        String id = c.getString(0);
 return ModelList;
}