Android IAP getPurchases NullPointerException

时间:2017-01-23 12:28:29

标签: java android

我已经在我的应用中实现了应用内结算功能,它适用于大多数设备,但有些设备报告了空指针异常。这是堆栈跟踪:

Fatal Exception: java.lang.RuntimeException: An error occured while executing doInBackground()
   at android.os.AsyncTask$3.done(AsyncTask.java:304)
   at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
   at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
   at java.util.concurrent.FutureTask.run(FutureTask.java:242)
   at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
   at java.lang.Thread.run(Thread.java:818)
Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'long java.lang.Long.longValue()' on a null object reference
   at android.os.Parcel.readException(Parcel.java:1552)
   at android.os.Parcel.readException(Parcel.java:1499)
   at com.android.vending.billing.IInAppBillingService$Stub$Proxy.getPurchases(IInAppBillingService.java:349)
   at com.vectorspace.roadcon.MyApplication$1$1.doInBackground(MyApplication.java:84)
   at com.vectorspace.roadcon.MyApplication$1$1.doInBackground(MyApplication.java:78)
   at android.os.AsyncTask$2.call(AsyncTask.java:292)
   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
   at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
   at java.lang.Thread.run(Thread.java:818)

我在OnServiceConnected中的Asynctask中运行上面的代码:

    @Override
    public void onServiceConnected(ComponentName name,
                                   IBinder service) {
        mService = IInAppBillingService.Stub.asInterface(service);


        AsyncTask<Object, Void, Bundle> getPurchasedItemTask = new AsyncTask<Object, Void, Bundle>() {


            @Override
            protected Bundle doInBackground(Object... objects) {
                try {
                    Bundle ownedItems = mService.getPurchases(3, getPackageName(), "inapp", null);

                    return ownedItems;
                } catch (RemoteException e) {
                    e.printStackTrace();
                }

                return null;
            }

我不知道出了什么问题,请帮忙。

0 个答案:

没有答案