I am attempting to implement Room in my Android application, but am getting the error error detail I find that the the found part for member_id is Integer while expected part is INTEGER, but I don't know how to set it and don't understand what is the different between this two. This is the table in my database database this is my Entity
@Entity(tableName = "Hierarchy")
public class Hierarchy {
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
@NotNull private int id;
@ColumnInfo(name = "catagory_id")
@NotNull private Integer catagory_Id;
@ColumnInfo(name = "member_id")
@NotNull private int member_id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@NotNull
public Integer getCatagory_Id() {
return catagory_Id;
}
public void setCatagory_Id(@NotNull Integer catagory_Id) {
this.catagory_Id = catagory_Id;
}
@NotNull
public Integer getMember_id() {
return member_id;
}
public void setMember_id(@NotNull Integer member_id) {
this.member_id = member_id;
}
}
I create the database in this form
database = Room.databaseBuilder(this, MyDataBase.class, "MedicineData.db")
.createFromAsset("Database/dataset.db")
.build();
}
Thank you very much for help me!
I tried to change the int to Integer in entity but it doesn't work.
In the found, the pre-packaged/asset database, you have category_id, on the expected i.e. the @Entity
annotated Hierarchy class you have catagory_id
i.e. an a rather than an e for the fourth character.
So probably change to use:-
@Entity(tableName = "Hierarchy")
public class Hierarchy {
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
@NotNull private int id;
@ColumnInfo(name = "category_id") /*<<<<<<<<<< CHANGED 4th character to e*/
@NotNull private Integer catagory_Id;
@ColumnInfo(name = "member_id")
@NotNull private int member_id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@NotNull
public Integer getCatagory_Id() {
return catagory_Id;
}
public void setCatagory_Id(@NotNull Integer catagory_Id) {
this.catagory_Id = catagory_Id;
}
@NotNull
public Integer getMember_id() {
return member_id;
}
public void setMember_id(@NotNull Integer member_id) {
this.member_id = member_id;
}
}
You may wish to also change all uses of catagory to category.