为什么我总是在这个复合订阅上获得 NPE,无论我把它放在片段中的哪个位置。
public CompositeSubscription subscriptions;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
subscriptions = new CompositeSubscription();
}
@Override
public void onStart() {
super.onStart();
subscriptions = new CompositeSubscription();
subscriptions//
.add(bindFragment(getActivity(), rxBus.toObserverable())//
.subscribe(new Action1<Object>() {
@Override
public void call(Object event) {
if (event instanceof Events.LocationUpdate) {
Log.v(TAG,"RXBUS CHANNEL 4!!!!");
Log.v(TAG, event.toString());
}
}
}));
}
我把订阅放在 onResume 中,同样的错误发生了。
java.lang.RuntimeException: Unable to start activity ComponentInfo{tv.loqoo.screen/com.loqooapps.Startup.Startup}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2202)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2252)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.loqooapps.Fragments.LoQooTV.FragLoQooTVScreenRegistration.onStart(FragLoQooTVScreenRegistration.java:297)
at android.app.Fragment.performStart(Fragment.java:1734)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:919)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1063)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1045)
at android.app.FragmentManagerImpl.dispatchStart(FragmentManager.java:1861)
at android.app.Activity.performStart(Activity.java:5291)