Tag: Android房间

房间+匕首2. NPE

使用房间+ LiveData + Dagger2 + Kotlin 分贝代码: @Database(entities = arrayOf(MonthlyBudget::class, Purchase::class), version = 1, exportSchema = false) @TypeConverters(DateTypeConverter::class) abstract class AppDatabase : RoomDatabase() { abstract fun budgetDAO(): BudgetDAO abstract fun purchaseDAO(): PurchaseDAO } 在提供db的dagger2中的方法 @Provides fun providesAppDatabase(context: Context): AppDatabase = Room.databaseBuilder(context, AppDatabase::class.java, “my-budget-db”).allowMainThreadQueries().build() 在匕首2中返回null的方法 @Provides @Singleton @Named(“CurrentMonthBudget”) fun provideCurrentMonthBudget(repository: AppRepository): MonthlyBudget = repository.currentMonthBudget() 对象的注入 @Inject […]