假设我有以下课程:
public abstract class AHuman
{
@DatabaseField(id = true)
protected String login;
}
以下两个类扩展了它:
@DatabaseTable(daoClass = UserDAO.class)
public class User extends AHuman
{
User() {}
@ForeignCollectionField
private ForeignCollection<Person> friends;
}
@DatabaseTable(daoClass = PersonDAO.class)
public class Person extends AHuman
{
Person() {}
}
当我在我的Android设备上编译并运行它时,我收到以下错误:
java.sql.SQLException: Could not call the constructor in class class
com.j256.ormlite.table.CustomDaoTest$A_DaoImpl
at com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22)
...
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
...
Caused by: java.lang.IllegalArgumentException: Foreign field class
>>>> com.j256.ormlite.table.CustomDaoTest$B does not have id field <<<<<<
at com.j256.ormlite.field.FieldType.configDaoInformation(FieldType.java:332)
此错误源自ForeignCollection<Person>
类中声明的User
。
显然,来自以下问题here,它来自于Person类没有声明“id”字段这一事实。
但是,不是从包含在Child对象中的abtract类继承的“id”字段吗?
答案 0 :(得分:0)
@Id字段是继承的。也许问题是你的构造函数不是公共的(使用默认说明符)