java - otto Could not dispatch event -


i want use otto in different activity. write code:

public class mainactivity extends actionbaractivity {      @bind(r.id.name)     textview name;      public static final float default_lat = 40.440866f;     public static final float default_lon = -79.994085f;     private static final float offset = 0.1f;     private static final random random = new random();       public static float lastlatitude = default_lat;     public static float lastlongitude = default_lon;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         butterknife.bind(this);     }      @onclick(r.id.button)     public void sayhi(button button){          busprovider.getinstance().post(new locationclearevent());          lastlatitude = default_lat;         lastlongitude = default_lon;         busprovider.getinstance().post(producelocationevent());          button.settext("hi");     }      @onclick(r.id.change)     public void changelocation(){         lastlatitude += (random.nextfloat() * offset *2) -offset;         lastlongitude += (random.nextfloat() * offset *2) -offset;         busprovider.getinstance().post(producelocationevent());     }      @onclick(r.id.view)     public void changeview() {         intent intent = new intent(this,mainactivity2activity.class);         startactivity(intent);     }      @override protected void onresume() {         super.onresume();          // register ourselves can provide initial value.         busprovider.getinstance().register(this);     }      @override protected void onpause() {         super.onpause();           // unregister when object no longer should on bus.         busprovider.getinstance().unregister(this);     }       @produce     static public locationchangedevent producelocationevent() {         // provide initial value location based on last known position.         return new locationchangedevent(lastlatitude, lastlongitude);     }      @subscribe     public void listenlocation(locationchangedevent event){         log.i("main", event.tostring());     } } 

second activity:

public class mainactivity2activity extends actionbaractivity {      @bind(r.id.location)     textview change;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main_activity2);         busprovider.getinstance().register(this);     }      @subscribe     public void onlocationchanged2(locationchangedevent event){         if(event == null) log.i("null","event null");         log.i("location change", event.tostring());         change.settext(event.tostring());     }       @override     protected void onresume() {         super.onresume();         busprovider.getinstance().register(this);     }      @produce     public locationchangedevent voichang(){         locationchangedevent = new locationchangedevent(1.1f,1.1f);         return a;     }      @override     protected void onpause() {         super.onpause();         busprovider.getinstance().unregister(this);     } } 

when click changeview start second activity. there error happened.

07-08 10:50:44.666  23212-23212/com.pp.kpm.test w/dalvikvm﹕ threadid=1: thread exiting uncaught exception (group=0xa6270288) 07-08 10:50:44.666  23212-23212/com.pp.kpm.test e/androidruntime﹕ fatal exception: main     java.lang.runtimeexception: unable start activity componentinfo{com.pathprint.kpm.test/com.pathprint.kpm.test.mainactivity2activity}: java.lang.runtimeexception: not dispatch event: class com.pathprint.kpm.test.locationchangedevent handler [eventhandler public void com.pathprint.kpm.test.mainactivity2activity.onlocationchanged2(com.pathprint.kpm.test.locationchangedevent)]: null             @ android.app.activitythread.performlaunchactivity(activitythread.java:2059)             @ android.app.activitythread.handlelaunchactivity(activitythread.java:2084)             @ android.app.activitythread.access$600(activitythread.java:130)             @ android.app.activitythread$h.handlemessage(activitythread.java:1195)             @ android.os.handler.dispatchmessage(handler.java:99)             @ android.os.looper.loop(looper.java:137)             @ android.app.activitythread.main(activitythread.java:4745)             @ java.lang.reflect.method.invokenative(native method)             @ java.lang.reflect.method.invoke(method.java:511)             @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:786)             @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553)             @ dalvik.system.nativestart.main(native method) 

i dont problem code.i confused in don't know why?


Comments