Android Room错误ProductDatabase_Impl不是抽象的,并且没有重写ProductDatabase中的抽象方法getProductDao()

Dev*_*rma 1 android overriding dao kotlin android-room

我在我的项目中使用 Kotlin 实现了 RoomDatabase。我不断收到以下错误。

error: ProductDatabase_Impl is not abstract and does not override abstract method getProductDao() 
in ProductDatabase
public final class ProductDatabase_Impl extends ProductDatabase {
Run Code Online (Sandbox Code Playgroud)

这是我的 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..}
Run Code Online (Sandbox Code Playgroud)

我在片段中使用了 dao:

val dao = ProductDatabase.getInstance(requireContext().applicationContext).productDao()
    repository = ProductRepository(dao)
    val factory = ProductViewModelFactory(repository)
Run Code Online (Sandbox Code Playgroud)

我确实搜索过它,但我发现的主要是使用 kapt 而不是 annotationProcessor,但我从一开始就使用 kapt 并且其他东西不起作用。这是我的房间依赖项。

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"
Run Code Online (Sandbox Code Playgroud)

Dev*_*rma 5

显然我创建了一个名为的包interface,它被检测为 Android Studio 中的一个目录。我将 dao 保留在该包中,这就是编译器找不到 dao 接口的原因。通过从该目录中删除 dao 解决了错误。