当前位置:   article > 正文

Caused by: org.greenrobot.eventbus.EventBusException: Subscriber class com.xxx.app.ui.activity

org.greenrobot.eventbus.eventbusexception: subscriber class activity and its

好记性不如烂笔头!!!

错误提示:Caused by: org.greenrobot.eventbus.EventBusException: Subscriber class com.xxx.app.ui.activity.WelcomeActivity and its super classes have no public methods with the @Subscribe annotation

 

长时间不开发新项目,你都不知道哪里错了。这里记录一下。     我这里是继承BaseActivity

EventBus在Activity和Fragment的父类里面注册完之后,会报上面的错误, 当时一脸懵逼 ? 

之前使用的  2.4.0的版本,没有添加注解也能直接使用。

现在使用的是:implementation 'org.greenrobot:eventbus:3.1.1'  就开始报错了。

其实注册完之后还需要你在父类里面加上@Subscribe注解才可以!

我的解决办法: 在父类中添加EventBus其中的一个函数

  1. @Subscribe
  2. public void onEventMainThread(MessageEvent event) {
  3. }

再运行就没问题了。   记住如果你的Fragment也有父类,记得也要添加并加上注解!

 

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/251195
推荐阅读
相关标签
  

闽ICP备14008679号