android - Parse.com relations with ParseObject -


i'm trying fix relation between 2 parseobjects: place & visit. tried method of extending objects parseobjects clean approach. problem related place object not saved.

place:

@parseclassname("place") public class place extends parseobject {      public place() {     }      private string title;     private parsegeopoint geopoint;      public string gettitle() {         return title;     }      public void settitle(string title) {         this.title = title;     }      public parsegeopoint getgeopoint() {         return geopoint;     }      public void setgeopoint(parsegeopoint geopoint) {         this.geopoint = geopoint;     }      //get distance current location     public double getdistance(parsegeopoint currentlocation) {         return this.geopoint.distanceinkilometersto(currentlocation);     } } 

visit

@parseclassname("visit") public class visit extends parseobject {      public visit() {     }      private long timestamp;     private long duration;      private place place;      public long gettimestamp() {         return timestamp;     }      public void settimestamp(long timestamp) {         this.timestamp = timestamp;     }      public long getduration() {         return duration;     }      public void setduration(long duration) {         this.duration = duration;     }      public place getplace() {         return place;     }      public void setplace(place place) {         this.place = place;     } } 

this way save backend:

final place place = new place();         place.settitle("home");          final visit visit = new visit();         visit.settimestamp(utils.getunixnow());         visit.setplace(place);          visit.saveeventually(new savecallback() {             @override             public void done(parseexception e) {                 if (e == null) {                     logger.d("visit " + place.gettitle() + " saved");                 } else {                     logger.d("place not saved, error " + e.getcode());                 }             }         }); 

both classes registered in myapplication class.

first of all: implementation of parse classes wrong.

1- remove field variables

2- create getters , setters following

public string gettitle() {     return get("title"); // 'title' column name in parse server table }  public void settitle(string title) {     put("title", title); } 

if want return parse object,

public parseobject  getplace () { // it's parseobject  not place     return get("place "); // 'place ' column name in parse server table }  public void setplace (parseobject title) { // it's parseobject  not place      put("place ", title); } 

creating objects

place place= parseobject.create(place .class); place.settitle("some title");  visit visit= parseobject.create(visit.class); visit.setplace(place); visit.save(); // or use saveinbackground(); 

in application class

    parseobject.registersubclass(visit.class);     parseobject.registersubclass(place.class);     parse.initialize(this); 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -