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

  1. Re-read list.size() immediately before each get() and keep index < size().
  2. Iterate with an Iterator or for-each instead of index-based access on a LazyList.
  3. Use peek(index) if you only want already-loaded entities and tolerate null.
  4. 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

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


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)