【发布时间】:2020-06-30 14:59:34
【问题描述】:
我在我的项目中使用 Kotlin 实现了 RoomDatabase。我不断收到以下错误。
error: ProductDatabase_Impl is not abstract and does not override abstract method getProductDao()
in ProductDatabase
public final class ProductDatabase_Impl extends ProductDatabase {
这是我的 Dao 接口和 ProductDatabase:
@Dao
interface ProductDao {
@Insert
suspend fun insertProduct(product: Product) : Long
@Insert
suspend fun insertAll(products: ArrayList<Product>) : List<Long>
@Update
suspend fun updateProduct(product: Product) : Int
@Query("SELECT * FROM product_table")
fun getAllProducts() : LiveData<List<Product>>
}
@Database(entities = [Product::class], version = 1)
abstract class ProductDatabase : RoomDatabase() {
abstract fun productDao(): ProductDao
abstract val productDao: ProductDao
companion object {..//Initialising..}
我在片段中使用了dao:
val dao = ProductDatabase.getInstance(requireContext().applicationContext).productDao()
repository = ProductRepository(dao)
val factory = ProductViewModelFactory(repository)
我确实搜索过它,但我发现大部分是使用 kapt 而不是 annotationProcessor,但我从一开始就使用了 kapt,其他的东西都不起作用。这是我的 Room 依赖项。
implementation "androidx.room:room-runtime:$roomVersion"
kapt "androidx.room:room-compiler:$roomVersion"
implementation "androidx.room:room-ktx:$roomVersion"
kapt "androidx.room:room-ktx:$roomVersion"
androidTestImplementation "androidx.room:room-testing:$roomVersion"
【问题讨论】:
标签: android kotlin overriding android-room dao