gpt4 book ai didi

java - Android 房间错误 : Dao class must be annotated with @Dao

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:20:36 24 4
gpt4 key购买 nike

我正在为我的 Android 应用程序使用 Room。我现在正在尝试设置我的数据库,但出现一条错误消息,指出 Dao 类必须使用 @Dao 进行注释。但是正如您在代码 fragment 中看到的那样,Dao 类使用@Dao 注释。有谁知道问题或我的错误可能出在哪里?这两个文件不在同一个文件夹中(DAO 在服务文件夹中,而另一个类在模型文件夹中)

设备.java

@Entity(tableName = "device")
public class Device {

@PrimaryKey(autoGenerate = true)
public int device_id;

@ColumnInfo(name = "identifier")
public String identifier;

@ColumnInfo(name = "language")
public int language;

@ColumnInfo(name = "searchFilter")
public int searchFilter;

public Device(String identifier, int language, int searchFilter){
this.identifier = identifier;
this.language = language;
this.searchFilter = searchFilter;
}
}

DeviceDAO.java

@Dao
public interface DeviceDAO {
@Insert(onConflict = OnConflictStrategy.REPLACE)
void addDevicePreferences(DifficultType difficultType);

@Query("SELECT * FROM device")
List<Device> selectAllDevicePreferences();

@Update(onConflict = OnConflictStrategy.REPLACE)
void updateDevicePreferences(Device device);
}

最佳答案

检查你的数据库类。当你定义 DAO 时,你一定使用了错误的类型(Device 而不是 DeviceDAO)。

不正确

公共(public)抽象设备 deviceDao();

正确

公共(public)抽象 DeviceDAO deviceDao();

希望这会奏效。谢谢

关于java - Android 房间错误 : Dao class must be annotated with @Dao,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47147288/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com