本文介绍了计费API V3 IabHelper NullPointerException异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

修改4/15:在IabHelper捕获空指针似乎已经停止了这个问题。我不再看到被抛出的异常,我会接受这个作为回答。


修改4/04:更深的下潜的一点点。有尝试catch块处理异常RemoteExceptions和JSONExceptions为queryPurchases方法,但没有NullPointerException异常处理。我所要尝试的就是包括空指针异常处理,以便IabHelper看起来像这样试图querySkuDetails时:

 赶上(NullPointerException异常E){
        抛出新IabException(IABHELPER_UNKNOWN_ERROR,空指针而清爽的库存。,E);
    }
 

我只是提出一个bug在此:

<一个href="https://$c$c.google.com/p/marketbilling/issues/detail?id=114">https://$c$c.google.com/p/marketbilling/issues/detail?id=114


修改3/25:好,仍然收到此崩溃......现在尝试获取上下文在以下摘录自IabHelper 3号线发生了:

  INT queryPurchases(库存INV,字符串ITEMTYPE)抛出JSONException,RemoteException的{
    logDebug(查询资项目,项目类型:+ ITEMTYPE);
    logDebug(包名+ mContext.getPackageName());
 

这是令人沮丧,因为在我的表现,我总是用我的应用程序的完整路径名名。

为例com.myappname.blah.ClassName

我也试过路过这,MyClass.this,getApplicationContext()来mHelper。然而,它们都随机地产生相同的空指针的结果从在野外设备。我也是在清单试图NAME =MyClass的。这是什么样子目前:

  mHelper =新IabHelper(MyClass.this,的myKey);
 


修改 13年3月18日:我还在接收例外,甚至部署在3/17新IabHelper版本。

我开始看到一个模式在这里的崩溃都在努力执行mContext.getPackageName时得到一个上下文时()。我很好奇,为什么这个工程对我所有的测试设备,我不能重现此碰撞,并且只似乎是一个小的设备数量。

下面是新的崩溃:

 显示java.lang.NullPointerException
    在com.myapp.util.IabHelper.queryPurchases(的SourceFile:836)
    在com.myapp.util.IabHelper.queryInventory(的SourceFile:558)
    在com.myapp.util.IabHelper.queryInventory(的SourceFile:522)
    在com.myapp.util.IabHelper $ 2.运行(的SourceFile:617)
    在java.lang.Thread.run(Thread.java:1019)
 

由IabHelper ...

引起

 行836:logDebug(包名+ mContext.getPackageName());
 


修改 13年3月17日:我看到有已经公布,在过去几个月很多bug修复,我会尝试最新的code可以在这里找到,看看是否能解决问题:

<一个href="https://$c$c.google.com/p/marketbilling/source/browse/v3/src/com/example/android/trivialdrivesample/util">https://$c$c.google.com/p/marketbilling/source/browse/v3/src/com/example/android/trivialdrivesample/util


在我的应用程序之一,我现在用的是计费API和样板code包含它。

我使用的计费API可通过SDK管理器的最新版本为2013年3月16号。

在我的活动,我用下面的查询清单:

 最后的名单,其中,字符串&GT; skuList =新的ArrayList&LT;字符串&GT;();
skuList.add(sku1);
skuList.add(sku2);
skuList.add(sku3);
如果(skuList!= NULL){
    如果(skuList.size()大于0){
        尝试 {
            mHelper.queryInventoryAsync(真,skuList,mGotInventoryListener);
        }赶上(例外五){
            。ACRA.getErrorReporter()handleException(E);
        }
    }
}
 

我收到从IabHelper类以下设备的野生多个NullPointerException异常报告。我无法重现的问题,并不能找到有关这些事故的任何信息,而就是为什么我张贴这个问题的原因。

我有无数的其他检查空值,并尝试/在计费API的一部分,包括在onQueryInventoryFinished的面向开发者catch块,所以我知道这个例外是不是从我的code抛出(因为我没有从我的任何应用程序的类捕获崩溃),而是从IabHelper本身被抛出。我没有修改IabHelper除此之外建议修复: http://stackoverflow.com/a/14737699

坠毁#1 Galaxy Nexus的

 显示java.lang.NullPointerException
    在com.myapp.util.IabHelper.querySkuDetails(的SourceFile:802)
    在com.myapp.util.IabHelper.queryInventory(的SourceFile:471)
    在com.myapp.util.IabHelper $ 2.运行(的SourceFile:521)
    在java.lang.Thread.run(Thread.java:856)
 

由IabHelper ...

引起

 行802:捆绑skuDetails = mService.getSkuDetails(3,mContext.getPackageName(),ITEM_TYPE_INAPP,querySkus);
 

崩溃#2三星GT-S5570L

 显示java.lang.NullPointerException
    在com.myapp.util.IabHelper.queryPurchases(的SourceFile:735)
    在com.myapp.util.IabHelper.queryInventory(的SourceFile:465)
    在com.myapp.util.IabHelper $ 2.运行(的SourceFile:521)
    在java.lang.Thread.run(Thread.java:1019)
 

由IabHelper ...

引起

 行735:捆绑ownedItems = mService.getPurchases(3,mContext.getPackageName(),ITEM_TYPE_INAPP,continueToken);
 

解决方案

修改4/15:在IabHelper捕获空指针似乎已经停止了这个问题。我不再看到被抛出的异常,我会接受这个作为回答。


修改4/04:更深的下潜的一点点。有尝试catch块处理异常RemoteExceptions和JSONExceptions为queryPurchases方法,但没有NullPointerException异常处理。我所要尝试的就是包括空指针异常处理,以便IabHelper看起来像这样试图querySkuDetails时:

 赶上(NullPointerException异常E){
        抛出新IabException(IABHELPER_UNKNOWN_ERROR,空指针而清爽的库存。,E);
    }
 

我只是提出一个bug在此:

<一个href="https://$c$c.google.com/p/marketbilling/issues/detail?id=114">https://$c$c.google.com/p/marketbilling/issues/detail?id=114

edit 4/15: Catching nullpointer in IabHelper appears to have stopped this problem. I am no longer seeing the exceptions being thrown, I'm going to accept this as an answer.


edit 4/04: A little bit of a deeper dive. There are try catch blocks that handle RemoteExceptions and JSONExceptions for the queryPurchases method, but no NullPointerException handling. What I am going to try is include NullPointer Exception handling so IabHelper looks like this when trying to querySkuDetails:

    catch (NullPointerException e) {
        throw new IabException(IABHELPER_UNKNOWN_ERROR, "NullPointer while refreshing inventory.", e);
    }

I just filed a bug on this:

https://code.google.com/p/marketbilling/issues/detail?id=114


edit 3/25: well, still receiving this crash... now it happens while trying to get a context at line 3 of the following excerpt from IabHelper:

int queryPurchases(Inventory inv, String itemType) throws JSONException, RemoteException {
    logDebug("Querying owned items, item type: " + itemType);
    logDebug("Package name: " + mContext.getPackageName());

This is frustrating because in my manifest I always use the full path name of my app for "name".

Example "com.myappname.blah.ClassName"

I've also tried passing this, MyClass.this, getApplicationContext() to mHelper. However they all produce the same NullPointer results randomly from devices in the wild. I also tried name=".MyClass" in the manifest. This is what it looks like currently:

mHelper = new IabHelper(MyClass.this, myKey);


edit 3/18/13: I am still receiving exceptions, even with the new IabHelper version deployed on 3/17.

I am starting to see a pattern here, that the crashes are all when trying to get a context when executing mContext.getPackageName(). I'm curious why this works on all of my test devices, and I can't reproduce this crash, and only seems to be on a small number of devices.

Here is the new crash:

java.lang.NullPointerException
    at com.myapp.util.IabHelper.queryPurchases(SourceFile:836)
    at com.myapp.util.IabHelper.queryInventory(SourceFile:558)
    at com.myapp.util.IabHelper.queryInventory(SourceFile:522)
    at com.myapp.util.IabHelper$2.run(SourceFile:617)
    at java.lang.Thread.run(Thread.java:1019)

Caused by IabHelper...

line 836: logDebug("Package name: " + mContext.getPackageName());


edit 3/17/13: I see that there have been many bug fixes published over the past several months, I will try the latest code available here and see if this resolves the problem:

https://code.google.com/p/marketbilling/source/browse/v3/src/com/example/android/trivialdrivesample/util


In one of my apps, I am using the billing API and the boilerplate code included with it.

I am using the latest version of billing API available via the SDK manager as of 3/16/2013.

In my activity, I query the inventory using the following:

final List<String> skuList = new ArrayList<String>();
skuList.add("sku1");
skuList.add("sku2");
skuList.add("sku3");
if (skuList != null) {
    if (skuList.size() > 0) {
        try {
            mHelper.queryInventoryAsync(true, skuList, mGotInventoryListener);
        } catch (Exception e) { 
            ACRA.getErrorReporter().handleException(e);
        }
    }
}

I am receiving multiple NullPointerException reports in the wild from the IabHelper class for the following devices. I can't reproduce the issue and can't find any information regarding these crashes, and is the reason why I am posting this question.

I have countless other checks for nulls and try/catch blocks in the "developer facing" part of the billing API, including within onQueryInventoryFinished, so I know this exception is not being thrown from "my code" (because I'm not capturing crashes from any of my app's classes), but instead is being thrown from within the IabHelper itself. I have not modified the IabHelper other than this recommended fix: http://stackoverflow.com/a/14737699

Crash #1 Galaxy Nexus

java.lang.NullPointerException
    at com.myapp.util.IabHelper.querySkuDetails(SourceFile:802)
    at com.myapp.util.IabHelper.queryInventory(SourceFile:471)
    at com.myapp.util.IabHelper$2.run(SourceFile:521)
    at java.lang.Thread.run(Thread.java:856)

Caused by IabHelper...

line 802: Bundle skuDetails = mService.getSkuDetails(3, mContext.getPackageName(), ITEM_TYPE_INAPP, querySkus);    

Crash #2 Samsung GT-S5570L

java.lang.NullPointerException
    at com.myapp.util.IabHelper.queryPurchases(SourceFile:735)
    at com.myapp.util.IabHelper.queryInventory(SourceFile:465)
    at com.myapp.util.IabHelper$2.run(SourceFile:521)
    at java.lang.Thread.run(Thread.java:1019)

Caused by IabHelper...

line 735: Bundle ownedItems = mService.getPurchases(3, mContext.getPackageName(), ITEM_TYPE_INAPP, continueToken);
解决方案

edit 4/15: Catching nullpointer in IabHelper appears to have stopped this problem. I am no longer seeing the exceptions being thrown, I'm going to accept this as an answer.


edit 4/04: A little bit of a deeper dive. There are try catch blocks that handle RemoteExceptions and JSONExceptions for the queryPurchases method, but no NullPointerException handling. What I am going to try is include NullPointer Exception handling so IabHelper looks like this when trying to querySkuDetails:

    catch (NullPointerException e) {
        throw new IabException(IABHELPER_UNKNOWN_ERROR, "NullPointer while refreshing inventory.", e);
    }

I just filed a bug on this:

https://code.google.com/p/marketbilling/issues/detail?id=114

这篇关于计费API V3 IabHelper NullPointerException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 23:58