buySubscription fails with a null pointer exception on Android
See original GitHub issueVersion 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:
- Created 5 years ago
- Comments:9 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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!
@marioot For, additional information, I’ve just updated to
2.0.2
release.prepare
method is deprecated and useinitConnection
instead. It is one of wishlist #236