android - 并且它的超类没有带有 Kotlin 和 DI 的 @Subscribe 注释的公共方法
问题描述
我已经检查了堆栈上的所有答案。但没有任何帮助。可能是 Kotlin + DI 的问题
所以我得到了一个例外,即 Eventbus 出于某种原因无法在演示者类中初始化自身。通过调试器,我看到从 onCreate 以正确方式执行的初始化方法。我使用与在其他类(Java 类)中使用的代码相同的代码,并且其他代码正常工作。你能否给一个建议,可能是一个问题
错误
Caused by: org.greenrobot.eventbus.EventBusException: Subscriber class com.myapp.mvp.ui.myprofile.MyProfileActivity and its super classes have no public methods with the @Subscribe annotation
at org.greenrobot.eventbus.SubscriberMethodFinder.findSubscriberMethods(SubscriberMethodFinder.java:67)
at org.greenrobot.eventbus.EventBus.register(EventBus.java:140)
at com.myapp.mvp.ui.myprofile.MyProfileActivity.onCreate(MyProfileActivity.kt:67)
at android.app.Activity.performCreate(Activity.java:7981)
at android.app.Activity.performCreate(Activity.java:7970)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
我的主讲课
import com.arellomobile.mvp.InjectViewState
import com.arellomobile.mvp.MvpPresenter
import com.myapp.UserProfileItemsList
import com.myapp.eventbus.VisitsEvent
import com.myapp.eventbus.UserEvent
import com.myapp.models.UserDescriptionModel
import com.myapp.mvp.model.interactor.myprofile.MyProfileInteractor
import com.myapp.utils.ActionsCountInfoCallback
import com.myapp.utils.UserCallback
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import java.util.ArrayList
import javax.inject.Inject
@InjectViewState
class MyProfilePresenter @Inject constructor(private val interactor: MyProfileInteractor) : MvpPresenter<MyProfileView>() {
private val userDescriptionList = ArrayList<UserDescriptionModel>()
override fun onFirstViewAttach() {
super.onFirstViewAttach()
setAllCurrentUserInfo()
setActionsCount()
}
fun setAllCurrentUserInfo() {
interactor.getAllCurrentUserInfo(UserCallback{ fsUser ->
viewState.setUserData(fsUser.name, fsUser.age, fsUser.country, fsUser.image)
userDescriptionList.addAll(UserProfileItemsList.initData(fsUser))
viewState.setList(userDescriptionList)
EventBus.getDefault().post(UserEvent(fsUser))
})
}
private fun setActionsCount() {
interactor.getActionsCountInfo(
ActionsCountInfoCallback{ visits, likes -> viewState.setActionsCount(visits, likes) })
}
@Subscribe
private fun updateActionsCount(event: VisitsEvent){
viewState.setActionsCount(event.getmVisits(), event.getmLikes())
}
fun registerSubscribers() {
if (!EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().register(this)
}
}
fun unsubscribe(){
EventBus.getDefault().unregister(this)
}
}
解决方案
MyProfileActivity 及其超类没有带有 @Subscribe 注释的公共方法
强调我的。private
在此处从您的函数中删除:
@Subscribe
private fun updateActionsCount(event: VisitsEvent)
推荐阅读
- asp.net-mvc - 模型无效时如何在局部视图中显示甜蜜警报
- unzip - 如何解压缩上传到 Azure Data Lake Store 的“.zip”文件?
- java - 如何在android改造中传递参数的值
- javascript - PrimeNg 在本地存储中坚持列调整大小状态
- python - 是否有更 Pythonic 的方式通过字符串名称访问函数?
- c# - Xamarin 窗体 WebView 滑动
- java - 如何转到 Thymleaf 中的 th:text 中的下一行?
- hadoop - 我们如何才能从 hdfs 联邦的一个命名空间中排除一些数据节点?
- java - 有没有办法使用java检查和释放数据库锁?
- c# - 统一:全方位的重力