greenrobot/greenDAO · error · DaoException

Loading of entity failed (null) at position

Error message

Loading of entity failed (null) at position 

What it means

After moving the cursor to the requested row, LazyList.loadEntity() calls daoAccess.loadCurrent(cursor, 0, true); if that returns null the row could not be mapped to an entity and a DaoException is thrown. loadCurrent returning null for a lazily-loaded list means the cursor row was invalid or the row failed entity creation.

Solutions

  1. Run queries on a single thread or obtain a thread-local copy with query.forCurrentThread().
  2. Re-execute the query (rebuild the LazyList) if the database may have changed.
  3. Wrap in try-catch for DaoException and fall back to a fresh query.list().
  4. Avoid holding a LazyList across transactions that delete rows it references.

Example fix

// before
LazyList<User> users = query.listLazy(); // reused across threads
User u = users.get(5); // intermittent DaoException
// after
Query<User> threadQuery = query.forCurrentThread();
List<User> users = threadQuery.list();
if (users.size() > 5) { User u = users.get(5); }
Defensive patterns

Strategy: retry

Try / catch

try { u = lazyList.get(i); } catch (DaoException e) { u = query.forCurrentThread().list().get(i); }

Prevention

When it happens

Trigger: LazyList.get(index) where cursor.moveToPosition succeeded but daoAccess.loadCurrent returned null at that position — e.g. the cursor was exhausted/invalidated by concurrent access or the row's data no longer matches the entity mapping.

Common situations: Concurrent modification of the database while iterating a LazyList (rows deleted between moveToPosition and loadCurrent), or sharing one query/LazyList across threads without forCurrentThread().

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of greenrobot/greenDAO@0bbb338e17 (2026-09-08). Data as JSON: /api/errors/17f4df749af32e98. Report an issue: GitHub.

Appendix: source

Thrown at DaoCore/src/main/java/org/greenrobot/greendao/query/LazyList.java:270

        } 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;
    }

    @Override
    public Iterator<E> iterator() {
        return new LazyIterator(0, false);

View on GitHub (pinned to 0bbb338e17)