当我尝试使用匕首2它给出了这个错误,我该怎么办,我在匕首2新的
e: /Users/stepanbezhuk/Documents/Work/Rebus/Movie/app/build/tmp/kapt3/stubs/debug/com/popularmovies/movies/Service/MessageWorking.java:11: error: @Provides methods must return a value (not void)
public final void messageConnected$app_debug(boolean networkStatus) {
模块1
@Module
open class MessageWorking @Inject constructor(private val context: Context) {
@Provides
internal fun messageConnected(networkStatus: Boolean) {
if (networkStatus) {
showMessage(message = "Connect")
} else {
showMessage(message = "Disconnect")
}
}
private fun showMessage(message: String) {
return Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
}
}
接口
@Component(modules = arrayOf(MessageWorking::class))
@Singleton
interface DaggerComponent {
fun messageConnected(networkStatus: Boolean)
}
1条答案
按热度按时间thigvfpy1#
这个
@Provides
注解意味着你必须提供一些东西回来。您没有返回类型messageConnected()
.您在dagger(toast)中执行ui操作,这非常奇怪,因为dagger的职责是提供依赖关系。
以下是一个简单的匕首介绍和如何设置的链接:https://medium.com/@skshayne/understanding-dagger-as-a-初学者-8ffe29bad429