Getter与任何领域无关 - Realm [英] Getter is not associated to any field - Realm

查看:198
本文介绍了Getter与任何领域无关 - Realm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am new to using Realm library and was trying to implement it in my android application. Just got stuck at a point where I am trying to section my listview based on the view type of a particular element in my json response.

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

I have tried to implement the sections with recycler view but the problem is I have 2 view types and addition of headers for those view types was causing an issue. Since Realm doesn't have the support of RecyclerAdapter, I created an implementation that will use a custom adapter that supports the RecyclerView.

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

So, I though I will use a ListView and try to use a simple interface for each of the Object type to determine the type and then insert the Headers based on the position of the group.

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

For some reason Realm is not allowing me to implement an interface in a class which extends 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

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

I have no idea why is complaining about this issue but its not compiling the project.

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

I read a few discussion about the issue here : link .. Apparently, there's an open discussion about this issue but any other help will be really appreciated.. Thank you

推荐答案

你的字段名称中有拼写错误,也不应该有前缀,所以它应该是sub j ect,getter必须是isSubject()

You have an typo in your field's name, also it shouldn't have prefix, so it would be "subject", and getter must be isSubject()

@Ignore
private boolean subject = false;


public boolean isSubject() {
    return subject;
}

有效的XHTML http://i60.tinypic.com/2eehr2b.png

这篇关于Getter与任何领域无关 - Realm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆