当前位置:   article > 正文

EventBusException: Subscriber class *** and its super classes have no public methods with the @Subsc_subscriber class com.shannon.mimo.library.bean.eve

subscriber class com.shannon.mimo.library.bean.eventmodel and its super clas

简述:

    去年的时候使用过一次EventBus,今天又遇到使用EventBus的项目,由于时隔一年多了所以写了一个Demo,但不行的是按照往常的用法却报出了这个异常:

EventBusException: Subscriber class *** and its super classes have no public methods with the @Subscribe annotation。说明一下,我用的是3.0.0版本的EventBus。

异常日志:

  1. ava.lang.RuntimeException: Unable to start activity ComponentInfo{com.lizhenya.eventbusdemo/com.lizhenya.eventbusdemo.MainActivity}: org.greenrobot.eventbus.EventBusException: Subscriber class com.lizhenya.eventbusdemo.MainActivity and its super classes have no public methods with the @Subscribe annotation
  2. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
  3. at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
  4. at android.app.ActivityThread.-wrap11(ActivityThread.java)
  5. at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
  6. at android.os.Handler.dispatchMessage(Handler.java:102)
  7. at android.os.Looper.loop(Looper.java:148)
  8. at android.app.ActivityThread.main(ActivityThread.java:5417)
  9. at java.lang.reflect.Method.invoke(Native Method)
  10. at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
  11. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  12. Caused by: org.greenrobot.eventbus.EventBusException: Subscriber class com.lizhenya.eventbusdemo.MainActivity and its super classes have no public methods with the @Subscribe annotation
  13. at org.greenrobot.eventbus.SubscriberMethodFinder.findSubscriberMethods(SubscriberMethodFinder.java:67)
  14. at org.greenrobot.eventbus.EventBus.register(EventBus.java:136)
  15. at com.lizhenya.eventbusdemo.MainActivity.onCreate(MainActivity.java:24)
  16. at android.app.Activity.performCreate(Activity.java:6237)
  17. at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
  18. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
  19. at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
  20. at android.app.ActivityThread.-wrap11(ActivityThread.java)
  21. at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
  22. at android.os.Handler.dispatchMessage(Handler.java:102)
  23. at android.os.Looper.loop(Looper.java:148)
  24. at android.app.ActivityThread.main(ActivityThread.java:5417)
  25. at java.lang.reflect.Method.invoke(Native Method)
  26. at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
  27. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

分析:

  在使用EventBus中在消息接收的页面需要使用下面的代码来注册:

EventBus.getDefault().register(this)
    onCreate时,EventBus扫描当前类,将onEventMainThread()等以onEvent开头的几个方法存储起来。OK,那么既然可以扫描出来为什么还会报出这样的异常错误,这个问题还得看源码。

解决方案:

    在onEventMainThread()方法上加注解“@Subscribe”;

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/251313
推荐阅读
相关标签
  

闽ICP备14008679号