2

I tried to save this object using Realm But I got this error

Error:(24, 9) error: Type java.util.ArrayList of field savedPath is not supported

Here is my code :

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(){}}

Thanx in advance

PriyankaChauhan
  • 953
  • 11
  • 26
alsalimi
  • 131
  • 1
  • 1
  • 10
  • i think you need to use List (the class in realm) and LatLng should be RealmObject or something like that – zombie Nov 29 '16 at 08:01
  • but i use android latlng so i can't make it extends realmObject , it is uneditable – alsalimi Nov 29 '16 at 08:03
  • there are some supported types that you can save other than that you need to create a RealmObject of it please check https://realm.io/docs/swift/latest/api/Classes/Object.html – zombie Nov 29 '16 at 08:06

1 Answers1

4

Both List and LatLng cannot be stored in Realm directly. You will need to create a model object for LatLng and then use a RealmList object containing your model objects.

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

You will need to manually convert objects of the LatLng class to the Location class when you are inserting/retrieving from the database.

rhari
  • 1,367
  • 1
  • 11
  • 19
  • i saved my points latlng like this { pointsarr.add(new LatLng(latitudeloc, longitudeloc));} how can i save to my model object – alsalimi Nov 29 '16 at 08:17
  • For every LatLng object, create a new Location object (as above) and store the getLatitude() and getLongitude() values from the LatLng object in the Location object – rhari Nov 29 '16 at 08:31
  • i got this error io.realm.exceptions.realmmigrationneeded exception realm migration must be provided – alsalimi Nov 29 '16 at 08:33
  • Have a look at http://stackoverflow.com/questions/33940233/realm-migration-needed-exception-in-android-while-retriving-values-from-realm – rhari Nov 29 '16 at 08:34
  • completly true :) thanx – alsalimi Nov 29 '16 at 08:49