android - 参数的类型必须是带有 @Entity 注释的类或其集合/数组

标签 android inheritance kotlin dao android-room

好的,所以我尝试按照本指南进行操作: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/

相关文章:

android - 表达式中 ObservableFields 的 get()

android - rxJava 中 doOnSuccess 与 onSuccess 的用例是什么

java - 即使路径正确,图像 URI 返回 null

Java - 创建伪 native 类型

c++ - 基指针中的派生对象如何调用基函数?

android - java.lang.StackOverflowError:堆栈大小8192KB蓝牙管理器

android - Kotlin - Dagger 2 - 组件不是由 Android 中的 Dagger 2 生成的

android - RecyclerView 项目宽度 layout_width =“match_parent” 与父级不匹配

安卓磨损 : Custom Notifications

java - 在Java中,new TestA()和TestA obj = new TestA()有什么区别?