0

I am not sure, what is up with this Library, but the results have always been inconsistent(at least for me).

I have ActivityA, ActivityB, FragmentB1 inside ActivityB. I will have to pass a String ID from ActivityA to ActivityB, FragmentB1. Since I am going to have a few more Fragments in ActivityB which also will be in need of this ID, I thought why not use EventBus. So, ActivityA became the Publisher and ActivityB, FragmentB1 became the Subscribers.

Defining the POJO for Event

public class EventUid {
    private final String Uid;

    public EventUid(String uid) {
        Uid = uid;
    }

    public String getUid() {
        return Uid;
    }
}

The code for ActivityA is as follows. The following code runs when I select a Spinner Item.

EventBus.getDefault().post(new EventUid(Uid));

The code for ActivityB, FragmentB1 is as follows. First I Register for the Event in onStart().

@Override
public void onStart() {
    super.onStart();
    EventBus.getDefault().register(this);
}

Then I UnRegister the Event in onStop().

@Override
public void onStop() {
    EventBus.getDefault().unregister(this);
    super.onStop();
}

Before subscribing to the Event, I define a String in ActivityB and FragmentB1.

private String ProductUid;

Finally, I subscribe to that Event in ActivityB and FragmentB1 as follows.

@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventUid(EventUid event) {
    ProductUid = event.getUid();
}

I am not sure where I might have gone wrong, but the ActivityB and FragmentB1 always returns a NullPointerException. Can someone point me the right way?

Thanks

EDIT: Adding LogCat. PS: The Activity, Fragment Names from this Question (named for easier understanding) will be different from LogCat.

--------- beginning of crash
06-10 12:44:20.342 3019-3019/blog.deshki.editor E/AndroidRuntime: FATAL EXCEPTION: main
                                                                  Process: blog.deshki.editor, PID: 3019
                                                                  java.lang.RuntimeException: Unable to start activity ComponentInfo{blog.deshki.editor/blog.deshki.editor.screens.media.MediaActivity}: java.lang.NullPointerException: Can't pass null for argument 'pathString' in child()
                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                      at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                      at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                      at android.os.Looper.loop(Looper.java:148)
                                                                      at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                   Caused by: java.lang.NullPointerException: Can't pass null for argument 'pathString' in child()
                                                                      at com.google.firebase.database.DatabaseReference.child(Unknown Source)
                                                                      at blog.deshki.editor.screens.media.MediaActivity.firebaseSettings(MediaActivity.java:291)
                                                                      at blog.deshki.editor.screens.media.MediaActivity.onCreate_aroundBody0(MediaActivity.java:267)
                                                                      at blog.deshki.editor.screens.media.MediaActivity$AjcClosure1.run(MediaActivity.java:1)
                                                                      at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:149)
                                                                      at com.frogermcs.androiddevmetrics.aspect.ActivityLifecycleAnalyzer.executeWithTracingIfEnabled(ActivityLifecycleAnalyzer.java:88)
                                                                      at com.frogermcs.androiddevmetrics.aspect.ActivityLifecycleAnalyzer.ajc$inlineAccessMethod$com_frogermcs_androiddevmetrics_aspect_ActivityLifecycleAnalyzer$com_frogermcs_androiddevmetrics_aspect_ActivityLifecycleAnalyzer$executeWithTracingIfEnabled(ActivityLifecycleAnalyzer.java:1)
                                                                      at com.frogermcs.androiddevmetrics.aspect.ActivityLifecycleAnalyzer.logAndExecute(ActivityLifecycleAnalyzer.java:66)
                                                                      at blog.deshki.editor.screens.media.MediaActivity.onCreate(MediaActivity.java:262)
                                                                      at android.app.Activity.performCreate(Activity.java:6237)
                                                                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                      at android.os.Looper.loop(Looper.java:148) 
                                                                      at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                      at java.lang.reflect.Method.invoke(Native Method) 
                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
06-10 12:44:20.358 1279-2221/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
user3314337
  • 341
  • 3
  • 13
  • @cricket_007 LogCat has been added. Please note, the Activity and Fragment names may differ, but the code related to EventBus is exactly line-by-line – user3314337 Jun 10 '17 at 07:03
  • If activity A is listening for activity B while activity B is in the foreground; actually activity A is stopped while it's backgrounded so it's not listening. EventBus is a bad choice for this case. Why don't you `startActivityForResult`? – Eugen Pechanec Jun 10 '17 at 07:20
  • @EugenPechanec I simply want to pass data from first Activity to second Activity (I can also Intents to pass data) or pass data from first activity to a Fragment in second Activity. The first activity is not listening for data from second Activity. Why would I need `startActivityForResult` – user3314337 Jun 10 '17 at 08:32
  • Where is your Firebase code? If the problem is in MediaActivity, show it. Please see about a [mcve] – OneCricketeer Jun 10 '17 at 16:31

0 Answers0