Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

PrimitiveCursorHelperGenerator.java:237 cursor access after cursor is closed #16

Open
allenz8512 opened this issue Mar 3, 2016 · 3 comments

Comments

@allenz8512
Copy link

Cause exception: "android.database.StaleDataException: Attempting to access a closed CursorWindow.Most probable cause: cursor is deactivated prior to calling this method."

@jaesga
Copy link

jaesga commented Jan 4, 2017

Same problem here while using a String[] on a model.

Tested on:

  • Android 24
  • LG Nexus 5X

@qu4sar
Copy link

qu4sar commented Aug 9, 2017

any suggestion ?

@qu4sar
Copy link

qu4sar commented Aug 9, 2017

in PrimitiveCursorHelper.java line 23 in the "getIntegers" method i find this :

public static List<Integer> getIntegers(SQLiteDatabase db, long objectId, String variable) {
   List<Integer> objects = new ArrayList<Integer>();
   Cursor cursor = db.rawQuery("SELECT value FROM MODEL_INT WHERE _object_id = ? AND _field_name= ?", new String[]{String.valueOf(objectId), variable});
   cursor.moveToFirst();
   while (!cursor.isAfterLast()) {
     objects.add(cursor.getInt(0));
     cursor.moveToNext();
     cursor.close();
   }
   return objects;
 }

I think that :

  **cursor.close();** 

need to stay outside the while cycle

@florent37 please can you check if it is right ?

Edit

Yes is this point, in the "PrimitiveCursorHelperGenerator.java" in the add method at line 33 , when you generate the method there is a

.addStatement("cursor.close()")
before of
.endControlFlow()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants