EventBusException:Subscriber class and its super classes have no public methods with the @Subscribe

Posted 舒泱

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了EventBusException:Subscriber class and its super classes have no public methods with the @Subscribe相关的知识,希望对你有一定的参考价值。

报错信息:

E/CrashReport: java.lang.RuntimeException: Unable to start activity ComponentInfo xxx Activity: org.greenrobot.eventbus.EventBusException: Subscriber class xxx Activity and its super classes have no public methods with the @Subscribe annotation
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3530)

原因:

官方源码SubscriberMethodFinder.java中写了,如果subscriberMethods为空,就会报这个错,也就是你没有实现Subscribe方法。

解决办法

如果你在程序里注册了订阅事件:EventBus.getDefault().register(this),那就必须得实现Subscribe方法。也许你想说你没有注册EventBus.getDefault().register(this),翻翻你当前的类继承的父类,也许父类中写了EventBus.getDefault().register(this)有没有默认的Subscribe方法。

Subscribe方法示例如下:

@Subscribe(threadMode = ThreadMode.MAIN)
fun onEvent(AnyEventType event) 
	/* Do something */
;

以上是关于EventBusException:Subscriber class and its super classes have no public methods with the @Subscribe的主要内容,如果未能解决你的问题,请参考以下文章