如何在RealmObject中保存ArrayList <latlng> savedPath

时间:2016-11-29 07:56:17

标签: android realm

我尝试使用Realm保存此对象但是我收到了此错误

  

错误:(24,9)错误:输入   java.util.Array字段列表   不支持savedPath

这是我的代码:

public  class TrackingInfo extends RealmObject {
   private int order_id;
   private double savedDistance;
   private double savedDuration;
   private ArrayList <LatLng>savedPath;

public int getOrder_id() {
    return order_id;
}

public void setOrder_id(int order_id) {
    this.order_id = order_id;
}

public double getSavedDistance() {
    return savedDistance;
}

public void setSavedDistance(double savedDistance) {
    this.savedDistance = savedDistance;
}

public double getSavedDuration() {
    return savedDuration;
}

public void setSavedDuration(double savedDuration) {
    this.savedDuration = savedDuration;
}

public ArrayList<LatLng> getSavedPath() {
    return savedPath;
}

public void setSavedPath(ArrayList<LatLng> savedPath) {
    this.savedPath = savedPath;
}

 public TrackingInfo(){}}

提前完成

1 个答案:

答案 0 :(得分:3)

List和LatLng都不能直接存储在Realm中。您需要为LatLng创建一个模型对象,然后使用包含模型对象的RealmList对象。

public class Location extends RealmObject {
    public Location() { }
    double latitude;
    double longitude;
}

RealmList<Location> savedPath = new RealmList<Location>();
//Add location objects to savedPath and store it in your TrackingInfo object

当您从数据库插入/检索时,您需要手动将LatLng类的对象转换为Location类。