Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference #166

Closed
janheinrichmerker opened this issue Apr 13, 2016 · 5 comments · Fixed by #208

Comments

@janheinrichmerker
Copy link

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)
@janheinrichmerker
Copy link
Author

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";
}

@kenumir
Copy link

kenumir commented Apr 14, 2016

+1

@dknchris
Copy link

dknchris commented Jul 9, 2016

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...

@serggl
Copy link
Member

serggl commented Oct 25, 2016

@heinrichreimer would you mind making PR with a fix?

@businessvivek3600
Copy link

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)

please explain how to completely resolve this issue

please explain in deep

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants