I'm trying to implement a simple database using Room and Dao, this is what I did
My entity:
public class Note {
@PrimaryKey(autoGenerate = true)
private int id;
@ColumnInfo(name = "title")
private String title;
}
I have also generated all getters and setters in the entity
but I don't include here because it's very long.
My Dao interface:
@Dao
public interface NoteDAO {
List<Note> getAllNotes();
}
My database class:
@Database(entities = Note.class, version = 1, exportSchema = false)
public abstract class NoteDatabase extends RoomDatabase {
private static NoteDatabase noteDatabase;
public static synchronized NoteDatabase getDatabase(Context context){
if (noteDatabase == null){
noteDatabase = Room.databaseBuilder(
context,
NoteDatabase.class,
);
}
return noteDatabase;
}
}
When I use List<Note> notes
and notes.toString()
, it only shows me the date and time, the title is null
, I also notice that in the Dao interface
, it raises 2 errors which are Cannot resolve symbol notes
and Cannot resolve symbol id
. I don't understand why it doesn't insert to the database. Can someone help me with this problem? Thanks for your help !