i use sugar orm in android app , know how make relationship between entities. thing have more emails , phone numbers (work, personal, home)
i have tried this:
i can add this..
contact contact = new contact(); contactitem contactitem = new contactitem(); contactitem.settype(1); contact.getitems.add(contactitem);
but when want load, have error. class cannot read sqlite3 database.
contact
public class contact extends sugarrecord { private string name; private string phonenumber; private string email; private boolean favourite; private string imagepath; @ignore private boolean visiblefirstletter; public list<contactitem> items; public contact() { //empty constructor } public contact(string name, string number, string email, boolean favourite, string imagepath) { this.name = name; this.phonenumber = number; this.email = email; this.favourite = favourite; this.imagepath = imagepath; this.items = new arraylist<>(); } public void setname(string name) {this.name = name; } public void setemail(string email) { this.email = email; } public void setphonenumber(string phonenumber) { this.phonenumber = phonenumber; } public void setfavourite(boolean favourite) { this.favourite = favourite; } public void setvisiblefirstletter(boolean visiblefirstletter) { this.visiblefirstletter = visiblefirstletter; } public string getname() { return name; } public string getemail() { return email; } public string getphonenumber() { return phonenumber; } public boolean isfavourite() { return favourite; } public boolean isvisiblefirstletter() { return visiblefirstletter; } public string getimagepath() { return imagepath; } public void setimagepath(string imagepath) { this.imagepath = imagepath; } public list<contactitem> getitems() { return items; } }
items
public class contactitem { string content; integer type; contact contact; public static final integer home = 0; public static final integer work = 1; public static final integer email = 2; public static final integer fax = 3; public contactitem() { //empty constructor } public contactitem(integer type, string content) { this.type = type; this.content = content; } public void settype(integer type) { this.type = type; } public void setcontent(string content) { this.content = content; } public string getcontent() { return content; } public integer gettype() { return type; } public contact getcontact() { return contact; } public void setcontact(contact contact) { this.contact = contact; } }
generally, should initialized contact
before find or update this. can contact
have method getname()
null.
in case, model.contact.getname()
is null object reference.
so, should check code:
contact contact = new contact("stepan", "09293293", stepan.stack@gmail.com, true); contact.save(); contact contact = sugarrecord.findbyid(contact.class, (long) 1);
or
you should tried code load contacts, seem findbyid
rows in contact
:
list<contact> contacts = sugarrecord.listall(contact.class);
in debugger android studio, please watch values. can incorrect in data.
Comments
Post a Comment