0

I have implemented the In-App Billing feature in my app, it works on most of the devices but some of them reported a null pointer exception. Here are the stacktrace:

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)

And I am running the above code inside an Asynctask in OnServiceConnected:

    @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;
            }

I have no idea what's wrong, please help.

Richard
  • 56
  • 1
  • 8
  • long data type doesnot support null value. – Ankush Bist Jan 23 '17 at 12:30
  • @Ankush Bist Thank you for your respond, but what does it mean? – Richard Jan 23 '17 at 12:32
  • @Ankush Bist I mean, which part of my code is the cause of the issue? the only value I passed to getPurchases is "3" – Richard Jan 23 '17 at 12:33
  • data parse exception. Means your api response results some null value. – Ankush Bist Jan 23 '17 at 12:33
  • that i can't say for now how this why this error is coming. But your logcat displays that null pointer issue on LONG type value. – Ankush Bist Jan 23 '17 at 12:35
  • 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) – Ankush Bist Jan 23 '17 at 12:35
  • Is it a known problem of the Google In-App Billing API? As I am calling the getPurchases method of the IInAppBillingService. – Richard Jan 23 '17 at 12:35
  • this is what displays the error and it also tells you the line numbers in Your 'MyApplication' activity where the actual error starts/came – Ankush Bist Jan 23 '17 at 12:36
  • maybe mService is null in doInBackground – Omer Jan 23 '17 at 12:36
  • i have not worked with In-App Billing. if you can forward me the source i can try to look after this. – Ankush Bist Jan 23 '17 at 12:37
  • @AnkushBist Thanks, I simply follow the official in App Billing code, nothing special. https://developer.android.com/google/play/billing/billing_integrate.html – Richard Jan 23 '17 at 12:40
  • what is the code at line `IInAppBillingService.java:349` – Amrut Bidri Jan 23 '17 at 12:50
  • check this answer http://stackoverflow.com/a/17836495/1576416 – Amrut Bidri Jan 23 '17 at 12:53

0 Answers0