EventBus使用

04-14 17:13:58.199 13449-13449/com.im E/AndroidRuntime: FATAL EXCEPTION: main
                                                        Process: com.im, PID: 13449
                                                        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.im/com.im.activity.LoginActivity}: org.greenrobot.eventbus.EventBusException: Subscriber class com.im.activity.LoginActivity and its super classes have no public methods with the @Subscribe annotation
                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3303)
                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3411)
                                                            at android.app.ActivityThread.-wrap12(Unknown Source:0)
                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1994)
                                                            at android.os.Handler.dispatchMessage(Handler.java:108)
                                                            at android.os.Looper.loop(Looper.java:166)
                                                            at android.app.ActivityThread.main(ActivityThread.java:7529)
                                                            at java.lang.reflect.Method.invoke(Native Method)
                                                            at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
                                                         Caused by: org.greenrobot.eventbus.EventBusException: Subscriber class com.im.activity.LoginActivity 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:136)
                                                            at com.im.activity.LoginActivity.onCreate(LoginActivity.java:125)
                                                            at android.app.Activity.performCreate(Activity.java:7383)
                                                            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1218)
                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3256)
                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3411) 
                                                            at android.app.ActivityThread.-wrap12(Unknown Source:0) 
                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1994) 
                                                            at android.os.Handler.dispatchMessage(Handler.java:108) 
                                                            at android.os.Looper.loop(Looper.java:166) 
                                                            at android.app.ActivityThread.main(ActivityThread.java:7529) 
                                                            at java.lang.reflect.Method.invoke(Native Method) 
                                                            at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) 
                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921) 
04-14 17:13:58.208 13449-13449/com.im I/Process: Sending signal. PID: 13449 SIG: 9
EventBus.getDefault().register(this); 注册

一定要写取消注册

EventBus.getDefault().unregister(this);

注册后,当前类中一定要有处理方法,不然会报错

@Subscribe(threadMode = ThreadMode.MAIN)
    public void XXX(String messageEvent) {
    }

https://www.jianshu.com/p/49c2a6a149e0
https://blog.csdn.net/zzb_bin/article/details/80229456
https://blog.csdn.net/u014733374/article/details/72625700
https://blog.csdn.net/u012317510/article/details/78935720

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值