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?
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.
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
Scanning file for viruses.
Sorry, we're still checking this file's contents to make sure it's safe to download. Please try again in a few minutes.
This file cannot be downloaded
Sorry, our virus scanner detected that this file isn't safe to download.