usr*_*ΛΩΝ 16 java android android-5.0-lollipop
今天我发现我的Android应用程序的应用程序崩溃报告涉及以下堆栈跟踪:
java.lang.NullPointerException: Attempt to invoke interface method 'android.os.Bundle com.android.vending.billing.IInAppBillingService.getPurchases(int, java.lang.String, java.lang.String, java.lang.String)' on a null object reference
at com.myapp.utils.IabHelper.queryPurchases(IabHelper.java:878)
at com.myapp.utils.IabHelper.queryInventory(IabHelper.java:572)
at com.myapp.utils.IabHelper.queryInventory(IabHelper.java:545)
at com.myapp.utils.IabHelper$2.run(IabHelper.java:645)
at java.lang.Thread.run(Thread.java:818)
Run Code Online (Sandbox Code Playgroud)
(由于自定义重新格式化,行号从原始版本更改 - 或者看起来像是原始版本)
通常,人们会修改自己的代码来检查未分配的类成员.问题是此代码是从Android SDK直接复制和粘贴的,因为IabHelperAndroid SDK 提供的类是实现应用内结算v3的良好起点
罪恶的线是第二个
logDebug("Calling getPurchases with continuation token: " + continueToken);
Bundle ownedItems = mService.getPurchases(3, mContext.getPackageName(), itemType, continueToken);
Run Code Online (Sandbox Code Playgroud)
似乎在调用方法时服务未连接.在Nexus 5设备上发生此错误(根据Developer Console)
Bil*_*ote 25
我修改了这段代码......
do {
logDebug("Calling getPurchases with continuation token: " + continueToken);
Bundle ownedItems = mService.getPurchases(3, mContext.getPackageName(), itemType, continueToken);
// ...
}
Run Code Online (Sandbox Code Playgroud)
为此......
do {
logDebug("Calling getPurchases with continuation token: " + continueToken);
if (mService == null || mContext == null) {
logError("Our service and/or our context are null. Exiting.");
return IABHELPER_UNKNOWN_ERROR;
}
Bundle ownedItems = mService.getPurchases(3, mContext.getPackageName(), itemType, continueToken);
// ...
}
Run Code Online (Sandbox Code Playgroud)
这几乎可以肯定是因为进程是异步运行的,并且当结果返回时,activity/app已经(或正在)关闭.
| 归档时间: |
|
| 查看次数: |
3619 次 |
| 最近记录: |