RealmList的Realm对象

时间:2017-02-09 17:10:13

标签: android realm realm-list

我是初学者Realm编程,我需要帮助。如何在Realm对象中创建和插入RealmList?我写了一些代码,我有语法错误。 这是我的主要Realm对象类

public class VinScannerHistoryModel extends RealmObject {
@Required
private String vinNumber;

@Required
private String userName;

@Required
private String status;


@Ignore
private RealmList<ImagesObject> imagesObjects;

public RealmList<ImagesObject> getImageList() {
    return imagesObjects;
}

public void setImageList(RealmList<ImagesObject> imageList) {
    this.imagesObjects = imageList;
}




@Required
private String key;


public String getPolygon() {
    return polygon;
}

public void setPolygon(String polygon) {
    this.polygon = polygon;
}

public String getKey() {
    return key;
}

public void setKey(String key) {
    this.key = key;
}

@Required
private String polygon;


public String getVinNumber() {
    return vinNumber;
}

public void setVinNumber(String vinNumber) {
    this.vinNumber = vinNumber;
}

public String getStatus() {
    return status;
}

public void setStatus(String status) {
    this.status = status;
}

public String getUserName() {
    return userName;
}

public void setUserName(String userName) {
    this.userName = userName;
}

}

这是一个真正的组合课程

public class ImagesObject extends RealmObject {
public String getImageName() {
    return imageName;
}

public void setImageName(String imageName) {
    this.imageName = imageName;
}
private String imageName;

}

我尝试像这样插入我的数据库

    private void insertIntoDatabase()
{
    mRealm.beginTransaction();

    ImagesObject imagesObject = mRealm.createObject(ImagesObject.class);
    VinScannerHistoryModel vinScannerHistoryModel = mRealm.createObject(VinScannerHistoryModel.class);
    vinScannerHistoryModel.setVinNumber(vinNumber.getText().toString());
    vinScannerHistoryModel.setStatus("Justsaved");
    if(Global.imagePath!=null && Global.imagePath.size()>0)
    {
        for (int i = 0; i < Global.imagePath.size(); i++) {
            imagesObject.setImageName(Global.imagePath.get(i));
        }

        vinScannerHistoryModel.getImageList().add(imagesObject);
    }


    if(checkBox.isChecked())
        vinScannerHistoryModel.setKey("1");
    else
        vinScannerHistoryModel.setKey("0");
    vinScannerHistoryModel.setPolygon(polygonAdapter.getItem(spinnerPosition).getId()+"");



    vinScannerHistoryModel.setUserName(vinScannerModel.getName());
    mRealm.commitTransaction();
}

正如我所说,我是初学者Realm编程,我不知道这是否正确? 当我运行我的应用程序时,我有这种语法错误

Error:(31, 17) error: Setter setImageList is not associated to any field

如何解决语法错误以及如何将一些数据插入RealmList? 如果有人知道解决方案,请帮助我 谢谢大家

0 个答案:

没有答案