GreenRobot例外:de.greenrobot.event.EventBusException:调用订阅者失败

时间:2015-10-27 14:51:03

标签: java android exception event-bus greenrobot-eventbus

我有时会遇到此异常。

我只是使用绿色机器人的标准方式,在视图,片段,活动,服务和应用程序之间,使用默认实例,并不时地使用一些stickyEvents。

我找不到与此例外相关的任何其他帖子。有什么想法或暗示开始调查吗?

事件总线运行良好(约20个事件,10个订阅者),一切都是用户触发的,因此在现场没有大的工作量。

完整的堆栈跟踪在这里:

de.greenrobot.event.EventBusException: Invoking subscriber failed
10-27 15:37:00.522 25414-25414/fr.tech.app..u E/AndroidRuntime:     at de.greenrobot.event.EventBus.handleSubscriberException(EventBus.java:518)
10-27 15:37:00.522 25414-25414/fr.tech.app..u E/AndroidRuntime:     at de.greenrobot.event.EventBus.invokeSubscriber(EventBus.java:500)
10-27 15:37:00.522 25414-25414/fr.tech.app..u E/AndroidRuntime:     at de.greenrobot.event.EventBus.postToSubscription(EventBus.java:429)
10-27 15:37:00.522 25414-25414/fr.tech.app..u E/AndroidRuntime:     at de.greenrobot.event.EventBus.postSingleEventForEventType(EventBus.java:410)
10-27 15:37:00.522 25414-25414/fr.tech.app..u E/AndroidRuntime:     at de.greenrobot.event.EventBus.postSingleEvent(EventBus.java:383)
10-27 15:37:00.522 25414-25414/fr.tech.app..u E/AndroidRuntime:     at de.greenrobot.event.EventBus.post(EventBus.java:263)
10-27 15:37:00.522 25414-25414/fr.tech.app..u E/AndroidRuntime:     at fr.u.app.u.Dialog.TastingNavigationDialog$1.onSelection(TastingNavigationDialog.java:42)
从MaterialDialog实例触发

错误:

  dialogBuilder = new MaterialDialog.Builder(context)
            .title(R.string.dialogTastingNavigationTripTitle)
            .negativeText(R.string.buttonCancel)
            .cancelable(false)
            .adapter(listAdapter, new MaterialDialog.ListCallback() {
                @Override
                public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
                    EventBus.getDefault().post(new TastingPageToEvent(listAdapter.list.get(which), which));
                    dialog.dismiss();
                }
            });

修改

我发现有一件事触发了异常,就是从一个片段发布一个stickyEvent。意图是即将出现的片段将能够恢复该粘性事件。

当转到Eventbus源时,它停在:

   void invokeSubscriber(Subscription subscription, Object event) {
        try {
            subscription.subscriberMethod.method.invoke(subscription.subscriber, event);
        } catch (InvocationTargetException e) {
            handleSubscriberException(subscription, event, e.getCause());
        } catch (IllegalAccessException e) {
            throw new IllegalStateException("Unexpected exception", e);
        }
    }

修改

以下是该方案。

public class TopEvent {
    String name;
    public TopEvent(String name){
        this.name = name;
    }
}

public class MyEvent extends TopEvent {
    String extraInfo;
    public MyEvent(String name, String extra){
        super(name);
        this.extraInfo = extra; 
    }
}

这是一个片段Tx:

...
EventBus.getDefault().postStickyEvent(new MyEvent("Stack","Overflow");
...

这是第二个片段Rx

...
String extra = EventBus.getDefault().getStickyEvent(MyEvent.class).extraInfo;
...

这是一项服务(获得奇怪行为的服务)

public class MyService extends Service {

    ...

    EventBus.getDefault().registerSticky(this)

    onEvent(TopEvent event){
       ...
       ...
    }

}

在onEvent结束时,抛出异常。好像它们是一些隐藏的行为,粘贴扩展事件(来自超级)发布,触发超级事件的非粘性事件。

2 个答案:

答案 0 :(得分:1)

这是由EventBus配置引起的:

EventBus.builder().throwSubscriberException(BuildConfig.DEBUG).installDefaultEventBus();

但是我很难理解为什么这个选项很有趣。事实上,我们(几乎)只看到失败的订户的例外,因为订户有另一个例外。但它经常被隐藏起来。那么为什么这有趣呢?

答案 1 :(得分:0)

你必须检查捕获事件的onEvent方法,并且事件总线会抛出此异常。