【发布时间】:2015-10-27 14:51:02
【问题描述】:
我有时会遇到此异常。
我只是以标准方式使用 green-robot,在视图、片段、活动、服务和应用程序之间,使用默认实例,并不时使用一些粘性事件。
我没有找到与此异常相关的任何其他帖子。有什么想法或提示可以开始我的调查吗?
事件总线运行良好(约 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();
}
});
编辑
我发现触发异常的一件事是从一个 Fragment 发布一个 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");
...
这是第二个 Fragment Rx
...
String extra = EventBus.getDefault().getStickyEvent(MyEvent.class).extraInfo;
...
这是一项服务(出现奇怪行为的服务)
public class MyService extends Service {
...
EventBus.getDefault().registerSticky(this)
onEvent(TopEvent event){
...
...
}
}
在 onEvent 结束时,抛出异常。好像它们是一些隐藏的行为,带有粘性扩展事件(来自超级)发布,触发超级事件的非粘性事件。
【问题讨论】:
-
Log cat 将您指向 TastingNavigationDialog 中的第 42 行 - 在那里查找您的错误或发布一些代码。
-
您使用的是哪个版本的 EventBus?我记得在旧版本中看到过这种异常,但他们在新版本中修复了它。
-
compile 'de.greenrobot:eventbus:2.4.0'因为他们最近 12 个月没有发布任何新闻:是的,我有最新的(也许是最后一个?!)版本。
标签: java android exception event-bus greenrobot-eventbus