greenrobot/greenDAO · error · DaoException
Could not move to cursor location
Error message
Could not move to cursor location
What it means
LazyList.loadEntity() positions the underlying SQLite cursor at the requested index before loading the entity. If cursor.moveToPosition(location) returns false — meaning the cursor cannot reach that row — a DaoException is thrown. This happens when the requested index exceeds the rows actually available in the result set.
Solutions
- Re-read list.size() immediately before each get() and keep index < size().
- Iterate with an Iterator or for-each instead of index-based access on a LazyList.
- Use peek(index) if you only want already-loaded entities and tolerate null.
- Wrap get() in try-catch for DaoException if the data may change concurrently.
Example fix
// before
for (int i = 0; i <= users.size(); i++) { User u = users.get(i); }
// after
for (User u : users) { /* u */ } Defensive patterns
Strategy: try-catch
Validate before calling
if (index >= 0 && index < lazyList.size()) { User u = lazyList.get(index); } Try / catch
try { u = lazyList.get(i); } catch (DaoException e) { lazyList = query.forCurrentThread().listLazy(); } Prevention
- Prefer for-each/Iterator over index access on LazyList.
- Never cache size() across database mutations.
- Use per-thread queries (forCurrentThread()) with LazyLists.
When it happens
Trigger: Calling LazyList.get(index) (directly or via List methods like size()+get) with an index >= the number of cursor rows, typically because the list was mutated/concurrently modified or the index came from a stale size() computation.
Common situations: Paging code that trusts a cached size() while the underlying data changed (row deleted by another transaction/thread), or an off-by-one loop like `for (i = 0; i <= list.size(); i++)`.
Related errors
- Loading of entity failed (null) at position
- This operation only works with cached lazy lists
- No entity found for query
- Offset cannot be set without limit
- JOINs are not supported for DELETE queries
AI-assisted analysis of greenrobot/greenDAO@0bbb338e17 (2026-09-08).
Data as JSON: /api/errors/8e9b90de23a2b48c.
Report an issue: GitHub.
Appendix: source
Thrown at DaoCore/src/main/java/org/greenrobot/greendao/query/LazyList.java:266
lock.unlock();
}
}
return entity;
} else {
lock.lock();
try {
return loadEntity(location);
} finally {
lock.unlock();
}
}
}
/** Lock must be locked when entering this method. */
protected E loadEntity(int location) {
boolean ok = cursor.moveToPosition(location);
if(!ok) {
throw new DaoException("Could not move to cursor location " + location);
}
E entity = daoAccess.loadCurrent(cursor, 0, true);
if (entity == null) {
throw new DaoException("Loading of entity failed (null) at position " + location);
}
return entity;
}
@Override
public int indexOf(Object object) {
loadRemaining();
return entities.indexOf(object);
}
@Override
public boolean isEmpty() {
return size == 0;
}View on GitHub (pinned to 0bbb338e17)