RandeeCao / marketbilling

Automatically exported from code.google.com/p/marketbilling
1 stars 0 forks source link

NullPointerException @IabHelper line 267 of the latest version #158

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
STEPS TO REPRODUCE:
1. lanch app will cause crash directly, because it throw an NullPointerException

DEVICE: LG P765

OUTPUT FROM ADB BUGREPORT ATTACHED:
(Note: The output from "adb bugreport" is required for all bug reports.)

NOTES:

Hi,guy:
 line 267 in IabHelper.java of the latest version:  if(!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty())

  mContext.getPackageManager().queryIntentServices(serviceIntent, 0) should return a list, but maybe return null

  I suggest such code should catch NullPointerException before released, because it is very ease to throw NullPointerException

Original issue reported on code.google.com by huster.z...@gmail.com on 7 Nov 2013 at 4:03

GoogleCodeExporter commented 8 years ago
Hi I got it too... and I've a lot of crash because of this error.
Can you please add some fix? 

This error seems to affect the whole user base (no version, carrier or device 
specific)

Original comment by stermi on 11 Nov 2013 at 2:01

GoogleCodeExporter commented 8 years ago
Anyway I think that you can simply make a little fix with a null check.
Take a look at this code: https://gist.github.com/StErMi/7413653

Original comment by stermi on 11 Nov 2013 at 2:05

GoogleCodeExporter commented 8 years ago
Thanks! But where "InappHelper.setInappSupported"? Anything in google about 
even setInappSupported method. InappHelper != IabHelper :\

Original comment by semt...@gmail.com on 18 Nov 2013 at 8:23

GoogleCodeExporter commented 8 years ago
Uops #3 my bad I've updated the code :)

InappHelper is my own helper :)

Original comment by stermi on 19 Nov 2013 at 2:25

GoogleCodeExporter commented 8 years ago
PackageManager.queryIntentServices() never returns null. 
(http://developer.android.com/reference/android/content/pm/PackageManager.html#q
ueryIntentServices(android.content.Intent, int))

I think the problem is that mContext somehow becomes null and that's why the 
NullPointerException.

I'm suddenly receiving a lot of these crashes from all types of devices. If 
anyone has a good fix, please share.

Original comment by catalin....@gmail.com on 2 Dec 2013 at 9:38

GoogleCodeExporter commented 8 years ago
I have a similar problem as well.  Adding a null check resolved the problem for 
me.

Intent serviceIntent = new 
Intent("com.android.vending.billing.InAppBillingService.BIND");
serviceIntent.setPackage("com.android.vending");

PackageManager pkgManager = mContext.getPackageManager();
List<ResolveInfo> intentServices = 
pkgManager.queryIntentServices(serviceIntent, 0);

if (intentServices != null && intentServices.isEmpty() == false) 
{
    // service available to handle that Intent
    mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
}
else 
{
    // no service available to handle that Intent
    if (listener != null) 
    {
        listener.onIabSetupFinished(new IabResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
                        "Billing service unavailable on device."));
    }
}

Original comment by nwmotog...@gmail.com on 7 May 2014 at 5:37

GoogleCodeExporter commented 8 years ago
By the way, the documentation for queryIntentServices() method says that if no 
result found, an empty list is returned, but in fact we have null very often 
for that method.

Original comment by Anastasi...@gmail.com on 8 May 2014 at 8:45

GoogleCodeExporter commented 8 years ago
PackageManager.queryIntentServices() really may return null on android 2.3.3. 
Test IAB in emulator without google play.

Original comment by viliam.d...@gmail.com on 4 Jul 2014 at 9:03