假设我有以下课程:
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”字段的事实。
但是,继承自abtract类的“id”字段不也包括在子对象中吗?
最佳答案
@id字段被继承。可能问题是构造函数不是公共的(使用默认说明符)