【发布时间】:2019-08-01 08:00:13
【问题描述】:
我正在尝试在 AppComponent 中注入 LatestChart 并解决 [Dagger/MissingBinding] 如果没有 @Inject 构造函数或 @Provides-annotated 方法就无法提供最新图表... 提前感谢您的帮助
最新图表.kt
class LatestChart {
@Inject
lateinit var context: Context
@Inject
lateinit var formatter: YearValueFormatter
lateinit var chart: LineChart
init {
App.appComponent.inject(this)
}
fun initChart(chart: LineChart) {
this.chart = chart
***
}
fun addEntry(value: Float, date: Float) {
***
}
}
private fun createSet(): LineDataSet {
***
}
return set
}
}
还有 AppComponent.kt
@Component(modules = arrayOf(AppModule::class, RestModule::class, MvpModule::class, ChartModule::class))
@Singleton
interface AppComponent {
***
fun inject(chart: LatestChart)
}
编译错误:
***AppComponent.java:8: error: [Dagger/MissingBinding] sn0w.test.crypto.chart.LatestChart cannot be provided without an @Inject constructor or an @Provides-annotated method. This type supports members injection but cannot be implicitly provided.
public abstract interface AppComponent {
^
A binding with matching key exists in component: sn0w.test.crypto.di.AppComponent
sn0w.test.crypto.chart.LatestChart is injected at
sn0w.test.crypto.activities.ChartActivity.latestChart
sn0w.test.crypto.activities.ChartActivity is injected at
sn0w.test.crypto.di.AppComponent.inject(sn0w.test.crypto.activities.ChartActivity)
【问题讨论】: