square / otto

An enhanced Guava-based event bus with emphasis on Android support.
http://square.github.io/otto/
Apache License 2.0
5.16k stars 847 forks source link

Posting event from service. #161

Closed shivamsingh closed 9 years ago

shivamsingh commented 9 years ago

java.lang.RuntimeException com.squareup.otto.Bus.throwRuntimeException(Bus.java:458) com.squareup.otto.Bus.dispatch(Bus.java:388) com.squareup.otto.Bus.dispatchQueuedEvents(Bus.java:369) com.squareup.otto.Bus.post(Bus.java:338) com..MainThreadBus.access$001(MainThreadBus.java:8) com..MainThreadBus$1.run(MainThreadBus.java:19) android.os.Handler.handleCallback(Handler.java:800) android.os.Handler.dispatchMessage(Handler.java:100) android.os.Looper.loop(Looper.java:194) android.app.ActivityThread.main(ActivityThread.java:5426) java.lang.reflect.Method.invokeNative(Native Method) java.lang.reflect.Method.invoke(Method.java:525) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842) com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) dalvik.system.NativeStart.main(Native Method) Caused by: com..setLocation(HomeFragment.java:984) com..HomeFragment.setLocation(HomeFragment.java:955) com..HomeFragment.access$001(HomeFragment.java:36) com..HomeFragment.setLocation(HomeFragment.java:249) java.lang.reflect.Method.invokeNative(Native Method) java.lang.reflect.Method.invoke(Method.java:525) com.squareup.otto.EventHandler.handleEvent(EventHandler.java:89) com.squareup.otto.Bus.dispatch(Bus.java:386) com.squareup.otto.Bus.dispatchQueuedEvents(Bus.java:369) com.squareup.otto.Bus.post(Bus.java:338) com..MainThreadBus.access$001(MainThreadBus.java:8) com..MainThreadBus$1.run(MainThreadBus.java:19) android.os.Handler.handleCallback(Handler.java:800) android.os.Handler.dispatchMessage(Handler.java:100) android.os.Looper.loop(Looper.java:194) android.app.ActivityThread.main(ActivityThread.java:5426) java.lang.reflect.Method.invokeNative(Native Method) java.lang.reflect.Method.invoke(Method.java:525) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842) com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) dalvik.system.NativeStart.main(Native Method)

shivamsingh commented 9 years ago

Using following as BUS.

public class MainThreadBus extends Bus {
    private final Handler mHandler = new Handler(Looper.getMainLooper());

    @Override
    public void post(final Object event) {
        if (Looper.myLooper() == Looper.getMainLooper()) {
            super.post(event);
        } else {
            mHandler.post(() -> MainThreadBus.super.post(event));
        }
    }
}
JakeWharton commented 9 years ago
Caused by: com..setLocation(HomeFragment.java:984)
com..HomeFragment.setLocation(HomeFragment.java:955)
com..HomeFragment_.access$001(HomeFragment_.java:36)
com..HomeFragment_.setLocation(HomeFragment_.java:249)

This is a problem in your code throwing an exception in the subscribe method.