如何在RealmObject模型类中使用List <double>

时间:2017-08-03 20:44:59

标签: android realm

在我的Android项目中,我有如下的模型类

dfList <- lapply(seq_along(bin.brks), function(m)      
  df[(df$len > bin.brks[m] & df$len <= bin.brks[m+1]),])

print(dfList)
# [[1]]
# [1] id  len
# <0 rows> (or 0-length row.names)

# [[2]]
#   id   len
# 1  1 11.25
# 2  2 11.75
# 3  3 12.00
# 4  4 12.00

# [[3]]
#   id  len
# 5  5 12.5

# [[4]]
#   id   len
# 6  6 13.25

# [[5]]
# [1] id  len
# <0 rows> (or 0-length row.names)

dfList <- Filter(function(i) nrow(i) > 0, dfList)

print(dfList)
# [[1]]
#   id   len
# 1  1 11.25
# 2  2 11.75
# 3  3 12.00
# 4  4 12.00

# [[2]]
#   id  len
# 5  5 12.5

# [[3]]
#   id   len
# 6  6 13.25

RealmList的自定义GSON类型适配器,如下所示

public class PilotMovement extends RealmObject {

private String type;
private RealmList<Coordinates> coordinates;

public PilotMovement() {
}

public PilotMovement(String type, RealmList<Coordinates> coordinates) {
    this.type = type;
    this.coordinates = coordinates;
}

public void setType(String type) {
    this.type = type;
}

public void setCoordinates(RealmList<Coordinates> coordinates) {
    this.coordinates = coordinates;
}

public class Coordinates extends RealmObject{
private double lon, lat;
public Coordinates(double lon, double lat) {
    this.lon = lon;
    this.lat = lat;
}
}

运行项目后显示编译错误如下

错误:任务&#39;:app:transformJackWithJackForDebug&#39;执行失败。

  

com.android.jack.ir.JNodeInternalError:java.lang.Exception:java.lang.IllegalStateException:不支持的类型java.lang.Object

如何解决这个问题的解决方案是什么?

1 个答案:

答案 0 :(得分:1)

考虑使用RealmList而不是list。但是我记得Realm不支持非RealmObjects的列表。因此,最好的方法是将坐标分离为:

public class LocationInfo extends RealmObject {
    private String type;
    private double lat;
    private double lon;
}