mehcode / rn-splash-screen

A JavaScript-controlled splash-screen for React Native designed to be run directly after the native splash-screen.
MIT License
350 stars 95 forks source link

Android null pointer exception #45

Closed AaronVasquez closed 7 years ago

AaronVasquez commented 7 years ago
java.lang.NullPointerException Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get()' on a null object reference 
    SplashScreen.java:67 com.mehcode.reactnative.splashscreen.SplashScreen.hide
    SplashScreenModule.java:31 com.mehcode.reactnative.splashscreen.SplashScreenModule.hide
    Method.java:-2 java.lang.reflect.Method.invoke
    Method.java:372 java.lang.reflect.Method.invoke
    BaseJavaModule.java:368 com.facebook.react.bridge.BaseJavaModule$JavaMethod.invoke
    JavaModuleWrapper.java:138 com.facebook.react.cxxbridge.JavaModuleWrapper.invoke
    NativeRunnable.java:-2 com.facebook.react.bridge.queue.NativeRunnable.run
    Handler.java:739 android.os.Handler.handleCallback
    Handler.java:95 android.os.Handler.dispatchMessage
    MessageQueueThreadHandler.java:31 com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage
    Looper.java:135 android.os.Looper.loop
    MessageQueueThreadImpl.java:208 com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run
    Thread.java:818 java.lang.Thread.run
mehcode commented 7 years ago

@AaronVasquez That looks like you're trying to hide the splash screen without showing it first. https://github.com/mehcode/rn-splash-screen/blob/master/android/src/main/java/com/mehcode/reactnative/splashscreen/SplashScreen.java#L25

It shouldn't crash though. Feel free to send a PR that adds an if statement there. Perhaps also a log on the else that warns the developer about hiding without showing.

AaronVasquez commented 7 years ago

Thanks for the quick response. I'm not an android dev, so not sure about best practices. What is the best way to log?

AaronVasquez commented 7 years ago

Also, it looks like you already check if it's null here: https://github.com/mehcode/rn-splash-screen/blob/master/android/src/main/java/com/mehcode/reactnative/splashscreen/SplashScreen.java#L21

mehcode commented 7 years ago

That's not the error. The error in question is stating that mActivity itself is null. Not that the reference it points to is null. This is telling me that line 21 in Show is never hit.

mehcode commented 7 years ago

Can I see your MainActivity.java file?

AaronVasquez commented 7 years ago

After following the documentation (https://github.com/mehcode/rn-splash-screen/blob/master/docs/android.md), I don't see the error any more. I must've forgotten to set up Android.