Getter与任何领域无关 – Realm

我是新手使用Realm库 ,并试图在我的Android应用程序中实现它。 刚刚陷入我试图根据我的json响应中的特定元素的视图类型对listview进行分区的问题。

我试图使用recycler view实现这些部分,但问题是我有2种视图类型,并且这些视图类型的标题添加导致了问题。 由于Realm没有RecyclerAdapter的支持,我创建了一个实现,它将使用支持RecyclerView的自定义适配器。

所以,我虽然会使用ListView并尝试为每个Object类型使用一个简单的接口来确定类型,然后根据组的位置插入Headers。

出于某种原因,Realm不允许我在扩展RealmObject的类中实现接口。

这就是这个类的样子:

 import com.google.gson.annotations.SerializedName; import io.realm.RealmObject; import io.realm.annotations.Ignore; import io.realm.annotations.PrimaryKey; public class TestClass extends RealmObject implements Subjects { @PrimaryKey @SerializedName("subjectID") private String subjectID; private String subjectDate; @SerializedName("subjectDescription") private String subjectDescription; public String getSubjectID() { return subjectID; } public void setSubjectID(String subjectID) { this.subjectID = subjectID; } public String getSubjectDate() { return subjectDate; } public void setSubjectDate(String subjectDate) { this.subjectDate = subjectDate; } public String getSubjectDescription() { return subjectDescription; } public void setSubjectDescription(String subjectDescription) { this.subjectDescription = subjectDescription; } @Override public boolean isSubjectA() { return true; } @Override public boolean isFoo() { return false; } @Override public boolean isBar() { return false; } } 

这是编译错误日志

 Error:(76, 20) error: Getter isSubject is not associated to any field. Note: Creating DefaultRealmModule Warning:File for type 'io.realm.DefaultRealmModule' created in the last round will not be subject to annotation processing. Warning:File for type 'io.realm.DefaultRealmModuleMediator' created in the last round will not be subject to annotation processing. 2 warnings 

我不知道为什么抱怨这个问题,但它没有编译项目。

我在这里阅读了一些关于这个问题的讨论: 链接 ..显然,有关于这个问题的公开讨论,但任何其他帮助将非常感谢..谢谢

您的字段名称中有拼写错误,也不应该有前缀,因此它将是“sub j ect”,getter必须是isSubject()

 @Ignore private boolean subject = false; public boolean isSubject() { return subject; } 

有效的XHTML http://sofzh.miximages.com/java/2eehr2b.png