今天在使用ormLite创建表的时候,想通过有参构造函数携带一个字段进去,没想到运行起来直接崩溃,并报了下面这个异常
Caused by: java.lang.IllegalArgumentException: Can't find a no-arg constructor for class com.xxx.xxx.xxx.xxx at com.j256.ormlite.table.DatabaseTableConfig.findNoArgConstructor(DatabaseTableConfig.java:196)
at com.j256.ormlite.table.DatabaseTableConfig.getConstructor(DatabaseTableConfig.java:126)
at com.j256.ormlite.table.TableInfo.<init>(TableInfo.java:94)
at com.j256.ormlite.dao.BaseDaoImpl.initialize(BaseDaoImpl.java:154)
at com.j256.ormlite.dao.BaseDaoImpl.<init>(BaseDaoImpl.java:128)
at com.j256.ormlite.dao.BaseDaoImpl.<init>(BaseDaoImpl.java:119)
at com.j256.ormlite.dao.BaseDaoImpl$5.<init>(BaseDaoImpl.java:921)
at com.j256.ormlite.dao.BaseDaoImpl.createDao(BaseDaoImpl.java:921)
at com.j256.ormlite.dao.DaoManager.createDao(DaoManager.java:72)
at com.j256.ormlite.field.FieldType.configDaoInformation(FieldType.java:341)
at com.j256.ormlite.dao.BaseDaoImpl.initialize(BaseDaoImpl.java:201)
at com.j256.ormlite.dao.BaseDaoImpl.<init>(BaseDaoImpl.java:128)
at com.j256.ormlite.dao.BaseDaoImpl.<init>(BaseDaoImpl.java:119)
at com.j256.ormlite.dao.BaseDaoImpl$5.<init>(BaseDaoImpl.java:921)
at com.j256.ormlite.dao.BaseDaoImpl.createDao(BaseDaoImpl.java:921)
at com.j256.ormlite.dao.DaoManager.createDao(DaoManager.java:72)
at com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper.getDao(OrmLiteSqliteOpenHelper.java:279)
看报错提示是找不到无参构造函数,这个时候再加一个无参的构造函数问题就解决了!
但是为什么会这样,还没来得及分析,之后找到问题所在再拿出来分析!