I\'m facing a problem with Room database, when trying to use insert method that I declared in Dao Class to write a data into database this error shows up:
AppDatabase Class
@Database(entities = {Task.class}, version = 1, exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {
public abstract TaskDao mTaskDao();
}
Model Class
@Entity
public class Task {
@PrimaryKey(autoGenerate = true)
private int uid;
@ColumnInfo(name = "task_name")
private String mName;
@ColumnInfo(name = "task_box")
private Integer mBox;
@ColumnInfo(name = "is_done")
private Integer mIsDone;
}
I figure it out, that error because there is no unique value in data (in primaryKey) so I make it auto generated,
Model Class
@Entity
public class Task {
@PrimaryKey(autoGenerate = true)
private int uid;
...
}