Skip to content
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

NullPointerException on calling SendSMSPackage.onActivityResult #46

Open
xavi opened this issue Apr 30, 2018 · 4 comments
Open

NullPointerException on calling SendSMSPackage.onActivityResult #46

xavi opened this issue Apr 30, 2018 · 4 comments

Comments

@xavi
Copy link

xavi commented Apr 30, 2018

Our logs show that the most popular crash of our app is

Caused by java.lang.NullPointerException
Attempt to invoke virtual method 'void com.tkporter.sendsms.SendSMSModule.onActivityResult(android.app.Activity, int, int, android.content.Intent)' on a null object reference
  com.tkporter.sendsms.SendSMSPackage.onActivityResult (SendSMSPackage.java:49)

So, I understand that the sendSms in this line is null.

That's called from the app's MainActivity.java

public void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  SendSMSPackage.getInstance().onActivityResult(requestCode, resultCode, data);
  ...

Any idea on what's the problem?
Thanks in advance.

@tkporter
Copy link
Owner

Hey @xavi, I'm taking a look now and it seems like getInstance() might be starting with instance as null and then creating a new instance without initializing sendSms. Could you check to see if instance is null when getInstance() is called by SendSMSPackage.getInstance().onActivityResult(requestCode, resultCode, data);?

That might help understand why sendSms is not initialized properly. Thanks!

@xavi
Copy link
Author

xavi commented May 15, 2018

Hi @tkporter, sorry for the late reply, I was busy with other things.

I can't check if instance is null when getInstance() is called because I can't reproduce it. This is a type of crash that some users of our app are having. I guess the only way to check it would be to put some logging in SendSMSPackage.getInstance(). We can do that but it will take time because requires a new release of the app (and a forked react-native-sms).

But looking at the react-native-sms code, I understand that the only way for this NullPointerException to occur is that instance is effectively null when getInstance() executes, and so sendSms is not initialized. If that were the case, do you know how it can be solved? Maybe there's a way to ensure that createNativeModules is called before MainActivity's onActivityResult? (Just guessing, I don't know what's the lifecycle of React Native's native modules.)

@xavi
Copy link
Author

xavi commented May 16, 2018

Is the line SendSMSPackage.getInstance().onActivityResult(requestCode, resultCode, data); in MainActivity#onActivityResult really necessary? That's the line that leads to the crash, so I tried deleting it, and SMS sending still seems to work.

@mousikosk
Copy link

mousikosk commented Jul 30, 2018

Hello @tkporter. I observed the same on a LG G4c with Android 6.0 and had reports from users with Android 5 and 4. I changed SendSMSPackage.java:48 to
public void onActivityResult(int requestCode, int resultCode, Intent data) { if (sendSms != null) { sendSms.onActivityResult(null, requestCode, resultCode, data); } }
and my app did not crash (but did not resume either of course) which leads me to believe that private SendSMSModule sendSms is null by that point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants