我收到lateinit
错误,但我没有看到问题
kotlin.UninitializedPropertyAccessException: lateinit property soldatDatabase has not been initialized
at pl.rybson.soldatlobby.di.RoomModule.provideServersDao(RoomModule.kt:37)
at pl.rybson.soldatlobby.di.RoomModule_ProvideServersDaoFactory.provideServersDao(RoomModule_ProvideServersDaoFactory.java:27)
at pl.rybson.soldatlobby.DaggerBaseApplication_HiltComponents_ApplicationC.getServersDao(DaggerBaseApplication_HiltComponents_ApplicationC.java:113)
at pl.rybson.soldatlobby.DaggerBaseApplication_HiltComponents_ApplicationC.getMainRepository(DaggerBaseApplication_HiltComponents_ApplicationC.java:127)
at pl.rybson.soldatlobby.DaggerBaseApplication_HiltComponents_ApplicationC.access$1800(DaggerBaseApplication_HiltComponents_ApplicationC.java:53)
at pl.rybson.soldatlobby.DaggerBaseApplication_HiltComponents_ApplicationC$SwitchingProvider.get(DaggerBaseApplication_HiltComponents_ApplicationC.java:431)
at pl.rybson.soldatlobby.ui.home.HomeViewModel_AssistedFactory.create(HomeViewModel_AssistedFactory.java:24)
at pl.rybson.soldatlobby.ui.home.HomeViewModel_AssistedFactory.create(HomeViewModel_AssistedFactory.java:12)
和 Module.kt
@Module
@InstallIn(ApplicationComponent::class)
object RoomModule {
private lateinit var soldatDatabase: SoldatDatabase
@Singleton
@Provides
fun provideRoom(@ApplicationContext context: Context): SoldatDatabase {
soldatDatabase = Room.databaseBuilder(
context,
SoldatDatabase::class.java,
"soldat.db"
)
.build()
return soldatDatabase
}
@Singleton
@Provides
fun provideServersDao(): ServersDao {
return soldatDatabase.serversDao()
}
}