Room dao cannot resolve table name and method


I’m trying to implement a simple database using Room and Dao, this is what I did
My entity:

@Entity(tableName = "notes")
public class Note implements Serializable {

    @PrimaryKey(autoGenerate = true)
    private int id;

    @ColumnInfo(name = "title")
    private String title;

    @ColumnInfo(name = "date_time")
    private String datetime;

    @ColumnInfo(name = "subtitle")
    private String subtitle;

    @ColumnInfo(name = "note_text")
    private String noteText;

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:

public interface NoteDAO {
    @Query("SELECT * FROM notes ORDER BY id DESC")
    List<Note> getAllNotes();

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertNote(Note note);

    void deleteNote(Note note);

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(
        return noteDatabase;
    public abstract NoteDAO noteDAO();

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 !


The code you have included in your question is fine (after adding the getters and setters) and then using:-

public class MainActivity extends AppCompatActivity {

    NoteDatabase db;
    NoteDAO dao;

    protected void onCreate(Bundle savedInstanceState) {

        db = NoteDatabase.getDatabase(this);
        dao = db.noteDAO();

        Note note1 = new Note();
        note1.setDatetime("2022-01-01 10:30");
        note1.setSubtitle("The First Note");
        note1.setNoteText("This is the note");

        for (Note n: dao.getAllNotes()) {
            Log.d("NOTEINFO","Title is " + n.getTitle() + " Date is " + n.getDatetime() + " blah blah ToString = " + n);
  • note the only amendment to the code copied from the question is the use of .allowMainThreadQueries in the databaseBuilder.

The result being:-

D/NOTEINFO: Title is NOTE001 Date is 2022-01-01 10:30 blah blah ToString = NOTE001 : 2022-01-01 10:30

However, adding :-

    Note note2 = new Note();
    //note1.setTitle("NOTE001"); //<<<<<<<<<<< OOOPS
    note2.setDatetime("2022-01-01 10:30");
    note2.setSubtitle("The Second Note");
    note2.setNoteText("This is the note");

Results in what you appear to be describing as per:-

D/NOTEINFO: Title is null Date is 2022-01-01 10:30 blah blah ToString = null : 2022-01-01 10:30

I believe you saying

I also notice that in the Dao interface, it raises 2 errors which are Cannot resolve symbol notes and Cannot resolve symbol id

Is perhaps the clue to the cause, which could be that you have the incorrect dependencies you should have 2 for Room:-

  1. the runtime library e.g. implementation '', and
  2. the compiler library e.g. annotationProcessor ''

Another possibility is that in addition to the getters and setters you have a constructor that doesn’t set correctly the title so it is left as null.

Answered By – MikeT

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published