当前位置:网站首页>Greendao reported an error in qigsaw, could not init daoconfig
Greendao reported an error in qigsaw, could not init daoconfig
2022-07-05 09:15:00 【Xu Jiajia 233】
Report errors
org.greenrobot.greendao.DaoException: Could not init DAOConfig
scene
- Use qigsaw
- The host module depends on greenDAO
- The plug-in module uses greenDAO
- The plug-in module uses greenDAO Report errors :Could not init DAOConfig
reason
- greenDAO The source code calls through reflection Properties class
- Host module loading greenDAO Of ClassLoader yes PathClassLoader
- Plug in module loading AbstractDao Implementation class ClassLoader yes QigsawClassLoader
- because QigsawClassLoader Not loaded in DAOConfig, So it will report an error .
How to check it out
The way to check is to check greenDAO Source code , The crash caused by plug-in , So it can be quickly inferred that ClassLoader The problem of , After verification, it was found that .
public DaoConfig(Database db, Class<? extends AbstractDao<?, ?>> daoClass) {
this.db = db;
try {
this.tablename = (String) daoClass.getField("TABLENAME").get(null);
Property[] properties = reflectProperties(daoClass);
this.properties = properties;
allColumns = new String[properties.length];
List<String> pkColumnList = new ArrayList<String>();
List<String> nonPkColumnList = new ArrayList<String>();
Property lastPkProperty = null;
for (int i = 0; i < properties.length; i++) {
Property property = properties[i];
String name = property.columnName;
allColumns[i] = name;
if (property.primaryKey) {
pkColumnList.add(name);
lastPkProperty = property;
} else {
nonPkColumnList.add(name);
}
}
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);
}
}
}
Property[] properties = new Property[propertyList.size()];
for (Property property : propertyList) {
if (properties[property.ordinal] != null) {
throw new DaoException("Duplicate property ordinals");
}
properties[property.ordinal] = property;
}
return properties;
}
Solution
There are still many solutions , Mainly based on business needs . The author will write some possible solutions :
- Add the plug-in to the greenDAO The relevant logic of is put into the host module
- If in the plug-in greenDAO There is not much logic in , As a temporary solution , Can be greenDAO The called class is defined again in the host .( It can only be a temporary plan )
- If not used in the host greenDao The logic of , It can be changed into a plug-in that directly depends on , Instead of loading in the host .
边栏推荐
- 2309. The best English letters with both upper and lower case
- 2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition
- [beauty of algebra] solution method of linear equations ax=0
- Wxss template syntax
- Jenkins Pipeline 方法(函数)定义及调用
- 2011-11-21 training record personal training (III)
- Introduction Guide to stereo vision (2): key matrix (essential matrix, basic matrix, homography matrix)
- AUTOSAR从入门到精通100讲(103)-dbc文件的格式以及创建详解
- Confusion matrix
- Applet global style configuration window
猜你喜欢
Creation and reference of applet
图神经网络+对比学习,下一步去哪?
高性能Spark_transformation性能
Solution to the problems of the 17th Zhejiang University City College Program Design Competition (synchronized competition)
Applet (global data sharing)
Applet (use of NPM package)
【阅读笔记】图对比学习 GNN+CL
OpenGL - Coordinate Systems
Confusing basic concepts member variables local variables global variables
生成对抗网络
随机推荐
2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition
什么是防火墙?防火墙基础知识讲解
高性能Spark_transformation性能
12. Dynamic link library, DLL
2011-11-21 training record personal training (III)
The location search property gets the login user name
nodejs_ 01_ fs. readFile
Blue Bridge Cup provincial match simulation question 9 (MST)
C [essential skills] use of configurationmanager class (use of file app.config)
Kotlin introductory notes (I) kotlin variables and non variables
Driver's license physical examination hospital (114-2 hang up the corresponding hospital driver physical examination)
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
Applet (subcontracting)
2309. 兼具大小写的最好英文字母
Codeforces Round #648 (Div. 2) E.Maximum Subsequence Value
notepad++
OpenGL - Lighting
Kotlin introductory notes (III) kotlin program logic control (if, when)
3D reconstruction open source code summary [keep updated]
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software