Android-inapp-billing-v3: Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference

Created on 13 Apr 2016  路  4Comments  路  Source: anjlab/android-inapp-billing-v3

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
       at com.anjlab.android.iab.v3.BillingBase.getPreferencesBaseKey(BillingBase.java:37)
       at com.anjlab.android.iab.v3.BillingCache.getPreferencesCacheKey(BillingCache.java:44)
       at com.anjlab.android.iab.v3.BillingCache.getPreferencesVersionKey(BillingCache.java:48)
       at com.anjlab.android.iab.v3.BillingCache.getCurrentVersion(BillingCache.java:109)
       at com.anjlab.android.iab.v3.BillingCache.reloadDataIfNeeded(BillingCache.java:113)
       at com.anjlab.android.iab.v3.BillingCache.includesProduct(BillingCache.java:77)
       at com.anjlab.android.iab.v3.BillingProcessor.isPurchased(BillingProcessor.java:141)
       ...
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:5422)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
PR Needed

Most helpful comment

You don't check if the WeakReference is still alive. I think you should also check if the reference is not yet enqueued.

protected String getPreferencesBaseKey() {
    if (contextReference.isEnqueued() || contextReference.get() == null)
        retrun null;
    return contextReference.get().getPackageName() + "_preferences";
}

All 4 comments

You don't check if the WeakReference is still alive. I think you should also check if the reference is not yet enqueued.

protected String getPreferencesBaseKey() {
    if (contextReference.isEnqueued() || contextReference.get() == null)
        retrun null;
    return contextReference.get().getPackageName() + "_preferences";
}

+1

This error keeps popping up in my Fabric console and there seems to be no fix we can implement in our apps? I don't wish to edit the library itself...

@HeinrichReimer would you mind making PR with a fix?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AbanoubWagdyWahib picture AbanoubWagdyWahib  路  9Comments

PSNAppz picture PSNAppz  路  4Comments

FranciscoE-Hudl picture FranciscoE-Hudl  路  9Comments

AdityaAnand1 picture AdityaAnand1  路  6Comments

mattiaferigutti picture mattiaferigutti  路  6Comments