未解析的引用显示在Kotlinandroid

inb24sb2  于 2023-01-24  发布在  Android
关注(0)|答案(2)|浏览(127)

我正在使用room persistence librarydagger

房间模块.kt

@Module
class RoomModule {

    @Provides
    @Singleton
    internal fun provideMoviesAppDatabase(application: Application): MoviesAppDatabase {
        return Room.databaseBuilder<MoviesAppDatabase>(application, KtMoviesAppDatabase::class.java, Keys.DATABASE_NAME)
                .addCallback(object : RoomDatabase.Callback() {
                    override fun onCreate(db: SupportSQLiteDatabase) {}
                    override fun onOpen(db: SupportSQLiteDatabase) {}
                })
                .build()
    }

}

kt电影应用程序数据库.kt

@Database(entities = [Movie::class], version = 1)
abstract class KtMoviesAppDatabase : RoomDatabase() {
    abstract fun getMovieDAO(): MovieDAO
}

我收到的错误:

{编辑}

我做了些改变

@Module
class RoomModule {

    @Provides
    @Singleton
    internal fun provideMoviesAppDatabase(application: Application): KtMoviesAppDatabase {
        return Room.databaseBuilder<KtMoviesAppDatabase>(application, KtMoviesAppDatabase::class.java, Keys.DATABASE_NAME)
                .addCallback(object : RoomDatabase.Callback() {
                    override fun onCreate(db: SupportSQLiteDatabase) {}
                    override fun onOpen(db: SupportSQLiteDatabase) {}
                })
                .build()
    }

}

我仍然有错误:

Unresolved reference: java
2g32fytz

2g32fytz1#

非常愚蠢的错误,因为我没有添加适当的依赖项

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.core:core-ktx:1.0.2'
ep6jt1vc

ep6jt1vc2#

我有这个错误早些时候,我解决了这个问题,通过更新Android Studio,你可以使用这个路径更新(帮助〉检查更新...)

相关问题