Open MrChriZ opened 6 years ago
Are you using hasNext()
here? Is it possible that you are running off the end of the results?
Feel free to reopen if you have more info.
I am facing the same issue.
CloseableIterator<EnConversationThread> iterator = enctDao.iterator(qBuilder.prepare());
while (iterator.hasNext()) {
EnConversationThread ecThread = iterator.next();
When I call next() in while loop, it throws "android.database.CursorIndexOutOfBoundsException: Index 3 requested, with a size of 3"
I think I'd worked around the problem in some kind of hacky way by the time Grey commented here - although I'm not currently working on the project to check. In answer to: Are you using hasNext() here? Is it possible that you are running off the end of the results?
In my case the .next is being done by OrmLites internal code as I'm simply iterating over a foreign collection: com.j256.ormlite.stmt.SelectIterator.nextThrow(SelectIterator.java:168) com.j256.ormlite.stmt.SelectIterator.next(SelectIterator.java:181) com.j256.ormlite.dao.LazyForeignCollection.toArray(LazyForeignCollection.java:216)
So I'm not sure how I could go off the end.
I use hasNext(). next() will be called only when iterator.hasNext() return true. Full error stack trace of ORM Lite is as follow. 02-14 17:35:22.808 W/System.err( 4583): android.database.CursorIndexOutOfBoundsException: Index 3 requested, with a size of 3 02-14 17:35:22.811 W/System.err( 4583): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:460) 02-14 17:35:22.811 W/System.err( 4583): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136) 02-14 17:35:22.811 W/System.err( 4583): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50) 02-14 17:35:22.811 W/System.err( 4583): at com.j256.ormlite.android.AndroidDatabaseResults.getString(AndroidDatabaseResults.java:134) 02-14 17:35:22.811 W/System.err( 4583): at com.j256.ormlite.field.types.StringType.resultToSqlArg(StringType.java:39) 02-14 17:35:22.811 W/System.err( 4583): at com.j256.ormlite.field.BaseFieldConverter.resultToJava(BaseFieldConverter.java:24) 02-14 17:35:22.811 W/System.err( 4583): at com.j256.ormlite.field.FieldType.resultToJava(FieldType.java:819) 02-14 17:35:22.811 W/System.err( 4583): at com.j256.ormlite.stmt.mapped.BaseMappedQuery.mapRow(BaseMappedQuery.java:60) 02-14 17:35:22.811 W/System.err( 4583): at com.j256.ormlite.stmt.SelectIterator.getCurrent(SelectIterator.java:270) 02-14 17:35:22.811 W/System.err( 4583): at com.j256.ormlite.stmt.SelectIterator.nextThrow(SelectIterator.java:161) 02-14 17:35:22.811 W/System.err( 4583): at com.j256.ormlite.stmt.SelectIterator.next(SelectIterator.java:173)
I used 'com.j256.ormlite:ormlite-android:4.48' for my project.
I'm facing the same issue. It occurs randomly. Version com.j256.ormlite:ormlite-android:5.0
@DatabaseTable(tableName = TABLE_NAME)
public class DBAccount {
@ForeignCollectionField(columnName = USERS)
private transient ForeignCollection<DBUser> users;
//...
public List<DBUser> getUserList() {
final List<DBUser> userList = new ArrayList<>();
if (users != null) {
userList.addAll(users); // Exception
}
return userList;
}
}
}
Stacktrace: android.database.CursorIndexOutOfBoundsException Index 1 requested, with a size of 1
android.database.AbstractCursor.checkPosition (AbstractCursor.java:468) android.database.AbstractWindowedCursor.isNull (AbstractWindowedCursor.java:92)
com.j256.ormlite.android.AndroidDatabaseResults.wasNull (AndroidDatabaseResults.java:218)
com.j256.ormlite.field.FieldType.resultToJava (FieldType.java:856)
com.j256.ormlite.stmt.mapped.BaseMappedQuery.mapRow (BaseMappedQuery.java:61)
com.j256.ormlite.stmt.SelectIterator.getCurrent (SelectIterator.java:284)
com.j256.ormlite.stmt.SelectIterator.nextThrow (SelectIterator.java:168)
com.j256.ormlite.stmt.SelectIterator.next (SelectIterator.java:181)
com.j256.ormlite.dao.LazyForeignCollection.toArray (LazyForeignCollection.java:216)
java.util.ArrayList.addAll (ArrayList.java:588)
I have the same problem: MainActivityandroid.database.CursorIndexOutOfBoundsException: Index 1 requested, with a size of 1
Is there some workaround? Thanks
Very similar issue :
Fatal Exception: java.lang.IllegalStateException
at com.j256.ormlite.stmt.SelectIterator.next + 191(SelectIterator.java:191)
at com.j256.ormlite.dao.LazyForeignCollection.toArray + 216(LazyForeignCollection.java:216)
at java.util.ArrayList.addAll + 588(ArrayList.java:588)
@ForeignCollectionField(columnName = MEMBERSHIPS)
public ForeignCollection<DBMembership> memberships;
public List<DBMembership> membershipList;
....
public List<DBMembership> getMembershipList() {
if (membershipList == null) {
membershipList = new ArrayList<>();
if (memberships != null) {
membershipList.addAll(memberships); // CRASH
}
}
return membershipList;
}```
I have some code as above. I'm getting strange crashes from Ormlite out in the wild.
ServiceBookings are a lazy foreign collection.
I'm getting the following error and stack trace from the allServiceBookingsFromVehicles.addAll(vehicle.getServiceBookings()); line above:
Any guesses as to what I'm doing wrong? The issue isn't easily repeatable unfortunately.