Okey, so I tried to follow this guide: https://medium.com/google-developers/7-pro-tips-for-room-fbadea4bfbd1 which led me to this code: https://gist.github.com/florina-muntenescu/1c78858f286d196d545c038a71a3e864
I tried to make my own example when I got the following two errors:
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.
I do not know if those two errors are related to each other, but I can't see where they occur and can there for not rule out that they are related.
@Entity
public class Data {
@PrimaryKey
uuid: String
title: String
}
My parent dao
@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)
}
My subclass 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>
}
I was getting same error for
@Insert
fun insertCars(vararg cars: List<Car>)
I fixed it by removing vararg
@Insert
fun insertCars(cars: List<Car>)
To anyone having the issue: Type of the parameter must be a class annotated with @Entity or a collection/array of it
This error is an indication that a Dao utilizing the BaseDao does not have a valid class for that datatype. For example here In this code the DataDao defines that class datatype to be used is type "Data" (line 23 of DataDao.kt) which is defined by the Data.kt class that contains the @Entity tag (line 22 of Data.kt).
So... if you are encountering this error, the error is NOT originating from the BaseDao interface but rather the Dao(s) that are using BaseDao.
I hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With