-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
你好,这个空指针怎么解决,在fragment里面加入 .compose(RxLife.with(this).bindToLifecycle()) #3
Comments
额,我现在oncreate调用 RxLife.with(this),初始化之后就不会出现这个问题了。。 |
Attempt to invoke virtual method 'void io.reactivex.subjects.Subject.onNext(java.lang.Object)' on a null object reference,其他地方还是会报错。 |
你调用代码我看一下,是否添加依赖 RxJava2,我看了代码,此处调用的是 lifecycleSubject.onNext()方法,lifecycleSubject已经在类实例化的时候初始化了 lifecycleSubject,点击查看LifecycleBridge代码,另外在Activity里使用有问题吗 ?是不是Fragment 的问题,Fragment只能是v4包下的 Fragment |
@huangxumin Fragment应该是动态添加的吧 ? |
有添加rxjava2依赖,activity也会出现这个问题,我觉得不是fragment的问题。我跳转activity也会出现这个问题。fargment是动态添加的
是v4的fragment,activity继承fragmentAvtivity. 这是activity和fragmrnt的调用代码: baseActivity里面:
// return RxLife.with(this).bindOnDestroy();
.subscribe(new Consumer() { |
原因我已经查到,类加载构造方法执行顺序的问题,可能会导致这个问题,我正在解决,随后发布代码 |
你试一下使用最新的1.1.3版本,能否解决问题 |
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void io.reactivex.subjects.Subject.onNext(java.lang.Object)' on a null object reference
at com.dhh.rxlife2.LifecycleBridge.onStateChanged(LifecycleBridge.kt:29)
at com.dhh.rxlife2.LifecycleBridgeBase.onStateChanged(LifecycleBridgeBase.kt:31)
at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:355)
at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:181)
at com.dhh.rxlife2.LifecycleBridgeBase.(LifecycleBridgeBase.kt:21)
at com.dhh.rxlife2.LifecycleBridge.(LifecycleBridge.kt:14)
at com.dhh.rxlife2.LifecycleBridge$Companion.get(LifecycleBridge.kt:19)
at com.dhh.rxlife2.RxLife.with(RxLife.kt:17)
at com.yunniu.isonic_smarthome.ui.fragment.MyHouseFragments.initView(MyHouseFragments.java:374)
at com.yunniu.isonic_smarthome.ui.fragment.MyHouseFragments.onCreateView(MyHouseFragments.java:145)
The text was updated successfully, but these errors were encountered: