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

Attempt to invoke interface method 'IInAppBillingService.getPurchases()' on a null object reference #310

Closed
eminsr opened this issue Nov 6, 2018 · 10 comments
Labels
🤖 android Related to android 🙏 help wanted Extra attention is needed

Comments

@eminsr
Copy link
Contributor

eminsr commented Nov 6, 2018

Version of react-native-iap

"react-native-iap": "^2.3.17"

Platforms you faced the error (IOS or Android or both?)

Android

Expected behavior

it should check if mService is null before calling getPurchases()

Actual behavior

It doesn't check if mService is null and throws this error
Attempt to invoke interface method 'android.os.Bundle com.android.vending.billing.IInAppBillingService.getPurchases(int, java.lang.String, java.lang.String, java.lang.String)' on a null object reference

Tested environment (Emulator? Real Device?)

Real Device Android 6.0

Steps to reproduce the behavior

Just call RNIap.getAvailablePurchases() after initConnection(),

const result = await RNIap.initConnection();
const purchases = await RNIap.getAvailablePurchases();

I temporarily fix it by setting a timeout for getAvailablePurchases()

@hyochan hyochan added 🙏 help wanted Extra attention is needed 🤖 android Related to android labels Nov 6, 2018
@hyochan
Copy link
Member

hyochan commented Nov 6, 2018

Can you show us in which line of code in Android it occurs? If it is wrapped with ensureConnection it should be fine because it is checking whether mService is null. Where do you think the problem is occurring?

Also, try below too.

const result = await RNIap.initConnection();
if (result) {
  const purchases = await RNIap.getAvailablePurchases();
}

@eminsr
Copy link
Contributor Author

eminsr commented Nov 6, 2018

I tried a couple of times, adding if statement seems like fixed it. I didn't understand why though it always returns the same thing. Anyway, thanks.

@eminsr eminsr closed this as completed Nov 6, 2018
@eminsr
Copy link
Contributor Author

eminsr commented Nov 8, 2018

I spoke too soon it still causing a crash.

I think there is a time gap between onBillingSetupFinished and onServiceConnected. initConnection() resolves on onBillingSetupFinished but until the service is connected mService is null.

To fix it in RNIapModule I simply catch the NullPointerException and reject the promise than when getAvailablePurchases() is rejected, in the catch I started another getAvailablePurchases() request.

If we can find a solution to resolve initConnection() after the mService is not null that would be great. But I can't think any way that doesn't involve a listener for mService.

@eminsr eminsr reopened this Nov 8, 2018
@hyochan
Copy link
Member

hyochan commented Nov 8, 2018

@eminsr Could you give a PR on what you've tried first? It might be helpful.

@eminsr eminsr mentioned this issue Nov 8, 2018
@hyochan
Copy link
Member

hyochan commented Nov 9, 2018

Just merged your PR lets see what we can do. Also @LinusU can you give some help with this issue? I remember you've updated some codes here.

@LinusU
Copy link
Member

LinusU commented Nov 9, 2018

@eminsr could we modify ensureConnection to wait for mService as well? That should work, right 🤔

@eminsr
Copy link
Contributor Author

eminsr commented Nov 9, 2018

@LinusU yea that should fix the issue.

@hyochan
Copy link
Member

hyochan commented Nov 13, 2018

@LinusU @eminsr Could someone give PR for this?

@eminsr
Copy link
Contributor Author

eminsr commented Nov 13, 2018

Maybe we can add a while loop to initConnection() but this doesn't seem like the right way to do it.

  @ReactMethod
  public void initConnection(final Promise promise) {
    ensureConnection(promise, new Runnable() {
      @Override
      public void run() {
        while(mService == null){
          Thread.sleep(250);
        }
        promise.resolve(true);
      }
    });
  }

@hyochan
Copy link
Member

hyochan commented Dec 27, 2018

I will close this since this is related #315

@hyochan hyochan closed this as completed Dec 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖 android Related to android 🙏 help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants