Skip to main content

This is the Crash Report I got from the Play Console: 

Type

java.lang.NullPointerException
Exception java.lang.NullPointerException:
at com.revenuecat.purchases.PurchaseParams$Builder.<init> (PurchaseParams.kt)
at com.xxxxxxxxxxxx.MainActivity.purchase (MainActivity.java:2103)
at com.xxxxxxxxxxxx.MainActivity.lambda$showPaywall$33 (MainActivity.java:2014)
at android.view.View.performClick (View.java:7792)
at android.widget.TextView.performClick (TextView.java:16112)
at android.view.View.performClickInternal (View.java:7769)
at android.view.View.access$3800 (View.java:910)
at android.view.View$PerformClick.run (View.java:30218)
at android.os.Handler.handleCallback (Handler.java:938)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loopOnce (Looper.java:226)
at android.os.Looper.loop (Looper.java:313)
at android.app.ActivityThread.main (ActivityThread.java:8751)
at java.lang.reflect.Method.invoke
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1135)

Here is my code:

    protected void purchase(Package purchasePackage) {
Log.d(TAG_REVENUECAT, "RC: Purchases.getSharedInstance().purchase");
Purchases.getSharedInstance().purchase(
new PurchaseParams.Builder(this, purchasePackage).build(), new PurchaseCallback() {
@Override
public void onCompleted(@NonNull StoreTransaction storeTransaction, @NonNull CustomerInfo customerInfo) {
if (customerInfo.getEntitlements().get(PREMIUM_ENTITLEMENT_ID) != null) {
if (Objects.requireNonNull(customerInfo.getEntitlements().get(PREMIUM_ENTITLEMENT_ID)).isActive()) {
// Unlock that great "pro" content
Log.d(TAG_REVENUECAT, "RC: Purchase completed");
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(MainActivity.this);
alertBuilder.setTitle(R.string.thankyou)
.setCancelable(false)
.setPositiveButton(android.R.string.ok, (dialog, id) -> {})
.show();
enablePremium(true);
}
}
}
@Override
public void onError(@NonNull PurchasesError purchasesError, boolean userCancelled) {
// No purchase
Log.e(TAG_REVENUECAT, purchasesError.toString());
Log.d(TAG_REVENUECAT, "Purchase error");
if (!userCancelled) {
showErrorAlert(purchasesError);
}
}
}
);
}
About 1% of users affected. I suspect “storeTransaction” or “customerInfo” having null. 
public void onCompleted(@NonNull StoreTransaction storeTransaction, @NonNull CustomerInfo customerInfo)

Should I check

customerInfo.getEntitlements() != null too?

 

 

 

Hi @orangutan,

Looks like this crash may be happening if `purchasePackage` is null when passed to the `PurchaseParams.Builder` constructor, since it’s a not null parameter. Can you confirm whether `purchasePackage` may be null on your code?

Let us know if you need any more help!

 

Thanks for your prompt reply.

 

You're right, for example, if the network isn't connected, getOfferings gives null AvailablePackages.

I've changed the code to check if purchasePackage is null.

I'll let you know the results in a few days.

 

Thanks!

 

Problem solved! Thanks a lot. 


Hi @orangutan,

Looks like this crash may be happening if `purchasePackage` is null when passed to the `PurchaseParams.Builder` constructor, since it’s a not null parameter. Can you confirm whether `purchasePackage` may be null on your code?

Let us know if you need any more help!

 

Thanks for your prompt reply.

 

You're right, for example, if the network isn't connected, getOfferings gives null AvailablePackages.

I've changed the code to check if purchasePackage is null.

I'll let you know the results in a few days.

 

Thanks!


Hi @orangutan,

Looks like this crash may be happening if `purchasePackage` is null when passed to the `PurchaseParams.Builder` constructor, since it’s a not null parameter. Can you confirm whether `purchasePackage` may be null on your code?

Let us know if you need any more help!


Reply