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)
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?
Most helpful comment
You don't check if the
WeakReferenceis still alive. I think you should also check if the reference is not yet enqueued.