0

I am starting InAppBillingService like this in a Fragment

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent serviceIntent =
            new Intent("com.android.vending.billing.InAppBillingService.BIND");
    serviceIntent.setPackage("com.android.vending");
    getActivity().bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);

}

Whenever I try to buy an item I get this error

FATAL EXCEPTION: AsyncTask #6
                                               Process: com.android.vending, PID: 15192
                                               java.lang.RuntimeException: An error occurred while executing doInBackground()
                                                   at android.os.AsyncTask$3.done(AsyncTask.java:325)
                                                   at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
                                                   at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
                                                   at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                                                   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                                                   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                                                   at java.lang.Thread.run(Thread.java:761)
                                                Caused by: java.lang.NullPointerException: Attempt to read from field 'long com.google.wireless.android.finsky.dfe.nano.an.b' on a null object reference
                                                   at com.google.android.finsky.billing.lightpurchase.s.a(SourceFile:5)
                                                   at com.google.android.finsky.billing.lightpurchase.h.doInBackground(SourceFile:27)
                                                   at android.os.AsyncTask$2.call(AsyncTask.java:305)
                                                   at java.util.concurrent.FutureTask.run(FutureTask.java:237)

The code execution never reaches the mServiceConn class. So I am guessing my code isn't able to start the service in the first place. What am I doing wrong.

theanilpaudel
  • 3,348
  • 8
  • 39
  • 67
  • You may refer with this [related post](https://stackoverflow.com/questions/8946228/java-lang-runtimeexception-an-error-occured-while-executing-doinbackground). It stated that you encountered those errors maybe because you're trying to display something on `doInBackground()`. `doInBackground` runs in a worker thread which cannot do any UI work (including showing Toasts, which is what you're doing). Instead, all UI work should be done on `onPostExecute()`. Also, make sure that you have the appropriate [permission](https://stackoverflow.com/a/18722321/5832311) in your `manifest.xml`. – abielita Jul 24 '17 at 15:32

1 Answers1

0

I think you are testing in app billing and at that time you face this problem. This is happen just because of the google play store's bugy version.
so no need to worry about that. Just test in app with older google play store version it will work fine.
for more information visit this question

EDIT : Aug 11th 2017
Now in new google play store version 8.0.73.R-all [0] [PR] 162689464 google fix this crash issue and I have successfully tested it on my devices so now you don't face this problem anymore. :)

Harin Kaklotar
  • 305
  • 7
  • 22