【问题标题】:Cannot resolve symbol in Room database无法解析 Room 数据库中的符号
【发布时间】:2022-11-30 16:56:18
【问题描述】:

我在 MainDao.class 中遇到问题:

  • 无法解析符号“notes_table”
  • 无法解析符号“id”
  • 无法解析符号“notes_table”
  • 无法解析符号“标题”
  • 无法解析符号“描述”

我怎样才能解决这个问题?

我的代码:

类 MainDao

@Dao
public interface MainDao{
    @Insert(onConflict = REPLACE)
    void insert(Notes notes);

    @Query("SELECT * FROM notes_table ORDER BY id DESC")
    List<Notes> getAll();

    @Query("Update notes_table SET title = :title, description = :description where id = :id")
    void update(int id, String title, String description);

      @Delete
void delete(Notes notes);}

类RoomDB.java

@Database(entities = Notes.class, version = 1, exportSchema = false)


   @Dao
    public abstract class RoomDB extends RoomDatabase {
    private static RoomDB database;
    private static String DATABASE_NAME = "NoteApp";

    public synchronized static RoomDB getInstance(Context context) {
        if (database == null) {
            database = Room.databaseBuilder(context.getApplicationContext(), RoomDB.class, DATABASE_NAME)
                    .allowMainThreadQueries()
                    .fallbackToDestructiveMigration()
                    .build();
        }
        return database;
    }

    public abstract MainDao MainDao();
}

课堂笔记.java

    @Entity(tableName = "notes_table")
public class Notes implements Serializable {

    @PrimaryKey(autoGenerate = true)
    int id = 0;

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

    @ColumnInfo(name = "description")
    String description = "";

    @ColumnInfo(name = "date")
    String date = "";
}

【问题讨论】:

    标签: java android database roomdb


    【解决方案1】:

    你应该改变这个 @Database(entities = Notes.class,version = 1,exportSchema = false)

    至 @Database(entities = {Notes.class},version = 1,exportSchema = false)

    【讨论】:

      猜你喜欢
      • 2016-11-20
      • 2018-11-11
      • 1970-01-01
      • 1970-01-01
      • 2022-01-05
      • 2016-02-07
      • 2015-12-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多