ReactNativeHost为null

时间:2018-03-08 17:05:50

标签: android react-native

我正在使用React native创建一些我的Android应用页面。因此,我正在创建扩展ReactActivity(FaceBook React Package)的活动。但我在ReactActivityDelegate.onResume,ReactActivityDelegate.onPause中随机获取NULL POINTER异常。基本上在ReactActivityDelegate中访问getReactNativeHost。我相信getReactNativeHost正在返回null。

我在MyApplication类中重写了实现ReactApplication的getReactNativeHost`。而reactnativehost实例在MyApplication类的onCreate中初始化

mReactNativeHost = new MyReactNativeHost(MyApplicationContext);                         
mReactNativeHost.getReactInstanceManager().createReactContextInBackground();

StackTrace是:

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.facebook.react.n.b()' on a null object reference
       at com.facebook.react.ReactActivityDelegate.onResume(SourceFile:124)
       at com.facebook.react.ReactActivity.onResume(SourceFile:66)
       at com.myreact.react.MyReactActivity.onResume(SourceFile:136)
       at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1269)
       at android.app.Activity.performResume(Activity.java:6770)
       at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3477)
       at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3546)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2795)
       at android.app.ActivityThread.-wrap12(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)
       at android.os.Handler.dispatchMessage(Handler.java:110)
       at android.os.Looper.loop(Looper.java:203)
       at android.app.ActivityThread.main(ActivityThread.java:6251)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)

0 个答案:

没有答案