Skip to main content
Question

java.lang.NullPointerException:

  • November 26, 2022
  • 2 replies
  • 304 views

Forum|alt.badge.img+5

I am getting the following error with the code below: ‘java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.revenuecat.purchases.EntitlementInfo.isActive()' on a null object reference’

 

Purchases.getSharedInstance().getCustomerInfo(new ReceiveCustomerInfoCallback() {
            @Override
            public void onReceived(@NonNull CustomerInfo customerInfo) {
                Log.i("RevenueCat", String.valueOf(customerInfo.getEntitlements()));
                Log.i("RevenueCat", String.valueOf(customerInfo.getEntitlements().getAll()));
                if (customerInfo.getEntitlements().get(premiumEntitlementID).isActive()) {
                    sharedPreferences.edit().putBoolean("premium", true).apply();
                }
                else {
                    sharedPreferences.edit().putBoolean("premium", false).apply();
                }
            }

            @Override
            public void onError(@NonNull PurchasesError purchasesError) {
                Log.i("RC error", String.valueOf(purchasesError));
            }
        });

 

.getEntitlements() is returning an empty dictionary too.

 

SDK version 5.4.0

 

Please could someone help me resolve this?

2 replies

sharif
RevenueCat Staff
Forum|alt.badge.img+9
  • RevenueCat Staff
  • 513 replies
  • November 30, 2022

I don’t have a lot of information to use here but it seems like this code line might be failing

customerInfo.getEntitlements().get(premiumEntitlementID).isActive()

I think Java is complaining that the result of .get(premiumEntitlementID) is null so you can’t call isActive() on it. Java should tell you the line number of the error. Can you try using the exact string instead of premiumEntitlementID? Also make sure you spelled the entitlement ID correctly in your app and in the dashboard.


Forum|alt.badge.img+5
  • Active Member
  • 10 replies
  • July 2, 2023

Hi -

Not sure if this will help, but I was running into this as well with the get(ENTITLEMENT_ID).isactive()

I believe mine is being caused by a new user that has never had the entitlement.

 

To get around the null pointer exception, i added the following ‘if’ before checking isActive()

(customerInfo.getEntitlements() != null && customerInfo.getEntitlements.get(ENTITLEMENT_ID) != null)

 

I hope that this helps


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings