假设我有以下类(class):
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”字段。
但是从抽象类继承的“id”字段不也包含在子对象中吗?
最佳答案
@Id 字段是继承的。也许问题在于您的构造函数不是公共(public)的(使用默认说明符)
关于android - ORMLite 中是否继承了 ID 字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25846498/