【发布时间】:2017-10-03 22:42:35
【问题描述】:
我正在将应用内计费集成到我的应用程序中。我使用了从谷歌开发网站获得的以下代码:
buttonDownload = (Button) findViewById(R.id.download);
buttonDownload.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// Intent i = new Intent(Intent.ACTION_VIEW);
// i.setData(Uri.parse(url2));
// startActivity(i);
// link.open();
@Override
public void onClick(View v) {
ArrayList skuList = new ArrayList();
skuList.add(inappid);
Bundle querySkus = new Bundle();
querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
Bundle skuDetails;
try {
skuDetails = mservice.getSkuDetails(3, getPackageName(),
"inapp", querySkus);
int response = skuDetails.getInt("RESPONSE_CODE");
if (response == 0) {
ArrayList<String> responseList = skuDetails
.getStringArrayList("DETAILS_LIST");
for (String thisResponse : responseList) {
JSONObject object = new JSONObject(thisResponse);
String sku = object.getString("productId");
String price = object.getString("price");
if (sku.equals(inappid)) {
System.out.println("price " + price);
Bundle buyIntentBundle = mservice
.getBuyIntent(3, getPackageName(), sku,
"inapp",
"bGoa+V7g/WqDXvKRqq+JTFn4uQRbPiQJEipf9RzJ");
PendingIntent pendingIntent = buyIntentBundle
.getParcelable("BUY_INTENT");
startIntentSenderForResult(
pendingIntent.getIntentSender(), 1001,
new Intent(), Integer.valueOf(0),
Integer.valueOf(0), Integer.valueOf(0));
}
}
}
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SendIntentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
我使用 android.test.purchased 来测试应用内计费。当我单击下载按钮时,它会购买没有缺陷的测试对象。但是,一旦我再次尝试购买它,应用程序就会崩溃,人们可以在我的应用程序中购买的商品必须可以多次购买。有人可以告诉我如何解决这个问题吗?
【问题讨论】:
-
请贴出崩溃的logcat
-
ABActivity.java的第 156 行正在抛出NullPointerException -
我需要改变什么来解决这个问题?
-
你需要更改
ABActivity.java的第156行...