16

we have an issue in our current app-version with the EventHandler from otto. We get a RuntimeException in our crash-log, with following description:

"Reason: java.lang.RuntimeException: Could not dispatch event: classcom.nameOfBrand.ui.events.SwitchFragmentEvent to handler [EventHandler public void com.nameOfBrand.ui.activities.MainActivity.onSwitchFragmentEvent(com.nameOfBrand.ui.events.SwitchFragmentEvent)]"

We have a button and in its onClickListener we fire an self-defined SwitchFragmentEvent. In some weird situations, the framework can't dispatch the Event and throws an RuntimeException.

The fragment with the button extends AbstractResultListFragment and this one extends AbstractFragment. We register the EventBus in the onResume of AbstractFragement and unregister it at onPause. Everything works fine, except at this one button :/

Does anyone have an idea or had ever to do with something like this?

UPDATE: Scompt was right. The RuntimeException was thrown from otto cause of a NullPointerException in our code. Thx

Tipp: Read your crash-logs until the end ;)

iFoukis
  • 274
  • 1
  • 2
  • 11
  • 1
    Do you have any additional information from the exception? There [should be](https://github.com/square/otto/blob/master/otto/src/main/java/com/squareup/otto/Bus.java#L386) a wrapped exception at that point. – Edward Dale Jun 13 '14 at 11:35
  • Oh, i see! Have not scrolled so far in the crashlog. In my case it's an NullPointer and as you said, wrapped inside this RuntimeException from the framework. Thanks – iFoukis Jun 13 '14 at 12:09
  • @scompt.com i don't have a wrapped exception. i have a `@Produce` method in my activity where a fragment in my activitie's viewpager is supposed to receive the event. but app clashes with the exception – Edijae Crusar Nov 30 '16 at 17:50

2 Answers2

9

There should be a wrapped exception at that point that will provide more information about the crash.

Edward Dale
  • 29,597
  • 13
  • 90
  • 129
  • 2
    How are you supposed to use this **protected** method "void dispatch(Object event, EventHandler wrapper)" ? – Raymond Chenon Mar 31 '15 at 10:14
  • 1
    How could this be a solution? it links me to a third party method which does not solve anything? I need to solve this problem with more advanced and clear explanation ! – blueware Sep 11 '17 at 09:54
1

If you use with AndroidAnnotation, add @UiThread to view treatment method. Note that the method should not be private.

Youngjae
  • 24,352
  • 18
  • 113
  • 198