java - Creating multiple tables using SugarORM gives IllegalStateException -


i have 2 classes, inventory , recipe. problem have cannot add items recipe table. following error message:

java.lang.illegalstateexception: caused by: android.database.sqlite.sqliteexception: table recipe has no column named name (code 1): , while compiling: insert or replace recipe(id,ingredients,how_to,name) values (?,?,?,?)

this happens when launch method gotosearchresults(view view), located in mainactivity.

inventory looks follows:

    import com.orm.sugarrecord;       public class inventory extends sugarrecord {         string foodtype;         string foodname;         string foodquantity;         public inventory(){       }  public inventory(string foodtype, string foodname, string foodquantity) {     this.foodtype = foodtype;     this.foodname = foodname;     this.foodquantity = foodquantity; }  public string getfoodtype() {     return foodtype; }  @override public string tostring() {     return  foodtype +             " " + foodname + '\'' +             " " +foodquantity + '\''             ; }  public void setfoodtype(string foodtype) {     this.foodtype = foodtype; }  public string getfoodquantity() {     return foodquantity; }  public void setfoodquantity(string foodquantity) {     this.foodquantity = foodquantity; }  public string getfoodname() {     return foodname; }  public void setfoodname(string foodname) {     this. foodname = foodname; } } 

the class recipe looks follows.

import com.orm.sugarrecord;  public class recipe extends sugarrecord {  string name; string ingredients; string howto; public recipe() { }  public recipe(string name, string ingredients, string howto) {     this.name = name;     this.ingredients = ingredients;     this.howto = howto;  }  public string getingredients() {     return ingredients; }  public void setingredients(string ingredients) {     this.ingredients = ingredients; }  public string gethowto() {     return howto; }  public void sethowto(string howto) {     this.howto = howto; }  public string getname() {     return name; }    public void setname(string name) {     this.name = name; }  @override public string tostring() {     return "recipe{" +             "name='" + name + '\'' +             ", ingredients='" + ingredients + '\'' +             ", howto='" + howto + '\'' +             '}'; }   } 

when try add items inventory table, use following 2 lines:

 inventory = new inventory(foodtype, foodname.gettext().tostring(), foodquantity.gettext().tostring());  inventory.save(); 

this works fine. items added inventory in way want them to.

however, when try put items recipe table, using following 2 lines (initialized in main activity). in main activity, have method, dummy method used debugging purposes.

public void gotosearchresults(view view){     intent intent = new intent(this, searchresults.class);     recipe = new recipe("filet mignon", "beef, potatoes", "use owen cook potatoes real -_^");     recipe.save();     startactivity(intent); } 

why doesn’t work? me, seems 2 classes , usage identical each other, , 1 works.

please try suggestion hope works :

  1. update sugar latest version 1.5 here
  2. try modify manifest configure : modify name of database, , correct location of class entities. here

i solve issue following steps above.


Comments