question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

buySubscription fails with a null pointer exception on Android

See original GitHub issue

Version of react-native-iap

react-native-iap: 1.4.0 react-native: 0.45.1

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

Android only (iOS works perfectly)

Expected behavior

After succesful initialisation and loading of subscriptions:

RNIap.prepare()
RNIap.getSubscriptions(itemSkus)

Buying a subscription should perform a transaction in play store: RNIap.buySubscription(sku)

Actual behavior

Buying a subscription fails with a runtime exception:

java.lang.NullPointerException: Attempt to invoke virtual method 'int com.android.billingclient.api.BillingClient.launchBillingFlow(android.app.Activity, $
  om.android.billingclient.api.BillingFlowParams)' on a null object reference                                                                                                                                 
       at com.dooboolab.RNIap.RNIapModule.buyItemByType(RNIapModule.java:332)                                                                              
       at java.lang.reflect.Method.invoke(Native Method)                                                                                                   
       at com.facebook.react.cxxbridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)                                                                
       at com.facebook.react.cxxbridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:162)                                                                
       at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)                                                                                
       at android.os.Handler.handleCallback(Handler.java:739)                                                                                              
       at android.os.Handler.dispatchMessage(Handler.java:95)                                                                                              
       at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)                                     
       at android.os.Looper.loop(Looper.java:158)                                                                                                          
       at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:199)                                                    
       at java.lang.Thread.run(Thread.java:818)                                                                                                            

Tested environment (Emulator? Real Device?)

  • Emulator
  • real device (react-native run-android)
  • real device (signed apk)

Steps to reproduce the behavior

In Android, try doing a subscription purchase flow

RNIap.prepare()
RNIap.getSubscriptions(itemSkus)
RNIap.buySubscription(sku)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
mariootcommented, Sep 2, 2018

@dooboolab good catch!

The component where I initially set up IAP was unmounting and closing the connection. Now it works!

Thanks a lot for your help!

1reaction
hyochancommented, Sep 3, 2018

@marioot For, additional information, I’ve just updated to 2.0.2 release. prepare method is deprecated and use initConnection instead. It is one of wishlist #236

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android In-app purchase NullPointerException - Stack Overflow
I couldn't from the code and test with virtual and physical devices since work fine. I'm pretty much sure that the error is...
Read more >
NullPointerException - Android Developers
On this page; Summary. Public constructors; Inherited methods. Public constructors. NullPointerException; NullPointerException. Android Developers.
Read more >
How to Fix and Avoid NullPointerException in Java - Rollbar
NullPointerException in Java occurs when a variable is accessed which is not pointing to any object and refers to nothing or null.
Read more >
Fix "java.lang.NullPointerException" in Android Studio
Hey Geeks, today we will see what NullPointerException means and how we can fix it in Android Studio. To understand NullPointerException ...
Read more >
NULL POINTER EXCEPTION WHEN LOADING XML ... - IBM
APAR status. Closed as program error. Error description. NullPointerException is thrown from the NamedDeclaration class when an XML document is loaded: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found