android - RealmObject is not valid, so it cannot be copied -


why code triggering a

java.lang.illegalargumentexception: realmobject not valid, cannot copied

error?

realm.begintransaction(); realm.delete(booking.class); final booking booking = realm.copyfromrealm(     new booking(         editfragment.getdestination(),         editfragment.getdate())); realm.committransaction(); 

however, if change exception not thrown:

realm.delete(booking.class); final booking booking = realm.createobject(     booking.class,     uuid.randomuuid().tostring()); booking.setdestination(editfragment.getdestination()); booking.setdate(editfragment.getdate()); 

what difference?

the booking class defined as:

public class booking extends realmobject {      @required     @primarykey     private string id;      @required     private string destination;      @required     private date date;      private int status;     private boolean isnotified;      public booking() {         this.id = uuid.randomuuid().tostring();         this.status = status_unavailable;     }      public booking(string destination, date date) {         this();         this.destination = destination;         this.date = date;     }      // getters , setters follow } 

edit:

found wrong: accidentally used copyfromrealm instead of copytorealm. looks autocomplete works against if not careful enough haha.

you have pass valid realmobject copyfromrealm(..) not sufficient create new instance on fly, because new object won't attached realm.

makes standalone in-memory copy of already persisted {@link realmobject}.

in second example creating new object , passing db persisted: 2 different operations.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -