greenrobot/greenDAO · error · DaoException
Could not init DAOConfig
Error message
Could not init DAOConfig
What it means
DaoConfig's constructor initializes keyIsNumeric and other metadata by reflecting over the entity and its Property fields; any Exception during this reflection (missing inner Properties class, illegal access, bad property types) is wrapped as DaoException "Could not init DAOConfig" with the cause attached. It happens when a DAO class is registered that greendao cannot reflect upon.
Solutions
- Regenerate DAO classes: re-run the greendao Gradle plugin build / annotation processor so <Entity>$Properties matches the entity.
- Inspect getCause() to see the underlying reflection error and fix the specific entity/property.
- Clean and rebuild the project to remove stale generated sources.
- Add ProGuard keep rules for generated classes: -keep class *$Properties { *; } and keep entity fields used by greendao.
Example fix
// after editing an entity, before: relying on stale generated code
// terminal:
./gradlew clean :app:generateGreenDaoSources :app:build
// build.gradle keep rule added:
-keepclassmembers class * extends org.greenrobot.greendao.Property { *; } Defensive patterns
Strategy: try-catch
Validate before calling
try {
Class.forName(entityClass.getName() + "$Properties");
} catch (ClassNotFoundException e) {
throw new IllegalStateException("DAO classes not generated for " + entityClass + "; run greendao generator");
} Try / catch
try {
daoSession = new DaoMaster(db).newSession();
} catch (DaoException e) {
Throwable cause = e.getCause(); // reflection error naming the bad entity
log.severe("DAOConfig init failed: " + cause + " — regenerate DAO classes");
} Prevention
- Always regenerate DAO classes after editing entities (greenDAO generator/Gradle plugin)
- Clean rebuild when entity and generated $Properties may be out of sync
- Add ProGuard keep rules for *$Properties and entity fields
- Inspect DaoException.getCause() to identify the offending entity
When it happens
Trigger: Registering a DAO whose generated $Properties class is missing or out of sync with the entity (stale/failed annotation-processor run), a Property referencing a field type reflection can't resolve, or code changes to an entity without regenerating DAO classes.
Common situations: Editing an entity class after code generation (greenDAO generator/Gradle plugin) without regenerating; renaming entities so Foo$Properties no longer exists; ProGuard removing generated Property fields in release builds.
Related errors
- No DAO registered for
- Expected unique result, but count was
- Cannot delete entity, key is null
- Entity does not exist in the database anymore
- Cannot update entity without key - was it inserted before?
AI-assisted analysis of greenrobot/greenDAO@0bbb338e17 (2026-09-08).
Data as JSON: /api/errors/b9b69861b740996d.
Report an issue: GitHub.
Appendix: source
Thrown at DaoCore/src/main/java/org/greenrobot/greendao/internal/DaoConfig.java:94
String[] nonPkColumnsArray = new String[nonPkColumnList.size()];
nonPkColumns = nonPkColumnList.toArray(nonPkColumnsArray);
String[] pkColumnsArray = new String[pkColumnList.size()];
pkColumns = pkColumnList.toArray(pkColumnsArray);
pkProperty = pkColumns.length == 1 ? lastPkProperty : null;
statements = new TableStatements(db, tablename, allColumns, pkColumns);
if (pkProperty != null) {
Class<?> type = pkProperty.type;
keyIsNumeric = type.equals(long.class) || type.equals(Long.class) || type.equals(int.class)
|| type.equals(Integer.class) || type.equals(short.class) || type.equals(Short.class)
|| type.equals(byte.class) || type.equals(Byte.class);
} else {
keyIsNumeric = false;
}
} catch (Exception e) {
throw new DaoException("Could not init DAOConfig", e);
}
}
private static Property[] reflectProperties(Class<? extends AbstractDao<?, ?>> daoClass)
throws ClassNotFoundException, IllegalArgumentException, IllegalAccessException {
Class<?> propertiesClass = Class.forName(daoClass.getName() + "$Properties");
Field[] fields = propertiesClass.getDeclaredFields();
ArrayList<Property> propertyList = new ArrayList<Property>();
final int modifierMask = Modifier.STATIC | Modifier.PUBLIC;
for (Field field : fields) {
// There might be other fields introduced by some tools, just ignore them (see issue #28)
if ((field.getModifiers() & modifierMask) == modifierMask) {
Object fieldValue = field.get(null);
if (fieldValue instanceof Property) {
propertyList.add((Property) fieldValue);
}
}View on GitHub (pinned to 0bbb338e17)