3

I'm getting this error when trying to update an objet from realm (0.82.1):

rowIndex > available rows: 0 > 0

Realm realm = null;

try{
    realm = Realm. getInstance ( context );
    RealmResults<Track> results = realm.allObjects( Track.class )
        .where()
        .equalTo("fileType", type)
        .equalTo("fileState", actualState)
        .equalTo("fileName", fileName)
        .findAll();

   //At this point result.size() = 1

   for( int i = 0; i < results.size(); i++ )
   {
       realm.beginTransaction();
       results.get( i ).setFileState(newState);
       realm.commitTransaction();
   }

}catch ( RealmException e ) {
    Log.d( TAG, e.getMessage());
}catch ( RealmIOException e ) {
    Log.d( TAG, e.getMessage());
}catch ( Exception e ) {
    Log.d( TAG, e.getMessage());
}
finally {
    if (realm != null) {
        realm.close();
    }
}

I have tried also with Iterator but I have the same error.

Summary:

  • It crashes every time. (I've seen it multiple times)
  • It is reproducable.
  • Experienced crashes on Android 4.4.4 (Samsung Galaxy S3), 5.0.1 (Samsung Galaxy Note4)

The crash is in the for loop. I capture the exception that is:

rowIndex 0 > 0 - invalid!
jni: ThrowingException 7, rowIndex > available rows: 0 > 0

Any solution?

mrpep
  • 131
  • 3
  • 12
  • What crash? At wich line? Export the stack trace and evidentiate the row that is generating the error. – Davide Lorenzo MARINO Aug 28 '15 at 12:10
  • Crash in the for loop. I capture the exception that is rowIndex 0 > 0 - invalid! jni: ThrowingException 7, rowIndex > available rows: 0 > 0 – mrpep Aug 28 '15 at 12:15

1 Answers1

4

This is happening because you are modifying a RealmResults you are iterating through. It's a known issue and you can follow its progress here: https://github.com/realm/realm-java/issues/640

As a workaround you can save the objects you want to modify in another list during the iteration and then iterating the new list to do the actual modification.

Emanuelez
  • 1,651
  • 10
  • 12