好的,所以我尝试按照本指南进行操作:https://medium.com/google-developers/7-pro-tips-for-room-fbadea4bfbd1 这导致我得到这个代码:https://gist.github.com/florina-muntenescu/1c78858f286d196d545c038a71a3e864
当我遇到以下两个错误时,我尝试制作自己的示例:
Error:Type of the parameter must be a class annotated with @Entity or a collection/array of it.
Error:Cannot use unbound generics in Dao classes. If you are trying to create a base DAO, create a normal class, extend it with type params then mark the subclass with @Dao.
我不知道这两个错误是否相互关联,但我看不出它们发生在哪里,并且不能排除它们是相关的。
@Entity
public class Data {
@PrimaryKey
uuid: String
title: String
}
我的父道
@Dao
abstract class BaseDao<in T> {
@Insert
abstract fun insert(obj: T)
@Insert
abstract fun insert(vararg obj: T)
@Update
abstract fun update(obj: T)
@Delete
abstract fun delete(obj: T)
}
我的子类 dao
@Dao
abstract class SubclassDao : BaseDao<Data> {
@Query("SELECT * FROM Data WHERE uuid = :id")
abstract fun getDataById(id: String): LiveData<Data>
@Query("SELECT * FROM BowelMovementEvent")
abstract fun getData(): List<Data>
@Query("SELECT * FROM BowelMovementEvent")
abstract fun getEventById(id: String): LiveData<Data>
}
最佳答案
我遇到了同样的错误
@Insert
fun insertCars(vararg cars: List<Car>)
我通过删除 vararg
修复了它@Insert
fun insertCars(cars: List<Car>)
关于android - 参数的类型必须是带有 @Entity 注释的类或其集合/数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48453948/