Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List<SomeObject> mList is not supported in Realm

I am working with Realm ORM for my application. My Application has three Model classes that extends RealmObject. In one of the class I have defined a List of object which is creating problem. my first class;

      public class Party extends RealmObject implements Parcelable{
            public String name;
            public String name_en;
            public String name_ne;
            public String address;
            public String phoneNumber;

    //get and setters

    //parceable

 }

My second class;

public class CreatePurchaseOrderRow extends RealmObject implements Parcelable {
    public String name;
    public float amount;
    public String specification;
    public String remarks;
    public Party party;

// getter setter

//parceable

}

And finally My third class implements List of objects of Second class. that is,

public class CreatePurchasOrder extends RealmObject implements Parcelable {
    public int num;
    public Date date;
    public List<CreatePurchaseOrderRow> createPurchaseOrderRows;

//getter setter

//parceable

}

the List feeds is creating problem.

i have the screenshot for error message here

Realm is not schemaless database. I tried finding the solutions but i cannot. Can anyone help me with this? Thanks in Advance

like image 345
Suresh Basnet Avatar asked Jun 30 '16 06:06

Suresh Basnet


1 Answers

RealmObjects can not have fields of type List<>(java.util.List), you have to use RealmList<> instead:

public class CreatePurchasOrder extends RealmObject implements Parcelable {
    public int num;
    public Date date;
    public RealmList<CreatePurchaseOrderRow> createPurchaseOrderRows;

    //getter setter

    //parceable
}

See also: https://realm.io/docs/java/latest/#many-to-many

like image 132
larsgrefer Avatar answered Oct 14 '22 23:10

larsgrefer