番石榴事件总线调度错误
Guava eventbus dispatching error
我正在开发一个 android 应用程序,我正在使用 guava eventbus。
我收到关于无法分派事件的模棱两可的错误。
我该如何调查此类问题?以及如何获得有关异常的更多信息?
这是一个示例异常消息:
04-12 20:46:35.829 9971-11208/xxx.android.init E/default﹕ Could not dispatch event: xxx.android.presentation.control.MainActivity@21139768 to public void xxx.android.presentation.control.MainActivity.showToast(xxx.core.event.EventShowToast)
ps:我把我们公司的class路径前缀换成了xxx
.
如果订阅者抛出异常,就会发生这种情况。
您可以通过在构造期间向您的 EventBus
提供 com.google.common.eventbus.SubscriberExceptionHandler
的实现,将默认记录器替换为您自己的记录器。
例如:
import com.google.common.eventbus.SubscriberExceptionContext;
import com.google.common.eventbus.SubscriberExceptionHandler;
class CustomExceptionHandler implements SubscriberExceptionHandler {
@Override
public void handleException(Throwable exception, SubscriberExceptionContext context) {
System.out.println("Handler '"+context.getSubscriber()+"' could not handle '"+context.getEvent().getClass().getName()+"'["+context.getEvent()+"]: " + exception.getMessage());
}
}
然后像这样使用它
EventBus eventBus = new EventBus(new CustomExceptionHandler());
我正在开发一个 android 应用程序,我正在使用 guava eventbus。 我收到关于无法分派事件的模棱两可的错误。 我该如何调查此类问题?以及如何获得有关异常的更多信息?
这是一个示例异常消息:
04-12 20:46:35.829 9971-11208/xxx.android.init E/default﹕ Could not dispatch event: xxx.android.presentation.control.MainActivity@21139768 to public void xxx.android.presentation.control.MainActivity.showToast(xxx.core.event.EventShowToast)
ps:我把我们公司的class路径前缀换成了xxx
.
如果订阅者抛出异常,就会发生这种情况。
您可以通过在构造期间向您的 EventBus
提供 com.google.common.eventbus.SubscriberExceptionHandler
的实现,将默认记录器替换为您自己的记录器。
例如:
import com.google.common.eventbus.SubscriberExceptionContext;
import com.google.common.eventbus.SubscriberExceptionHandler;
class CustomExceptionHandler implements SubscriberExceptionHandler {
@Override
public void handleException(Throwable exception, SubscriberExceptionContext context) {
System.out.println("Handler '"+context.getSubscriber()+"' could not handle '"+context.getEvent().getClass().getName()+"'["+context.getEvent()+"]: " + exception.getMessage());
}
}
然后像这样使用它
EventBus eventBus = new EventBus(new CustomExceptionHandler());