So I call the purchase:

unlock_full_version.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { bp = BillingProcessor.newBillingProcessor(MainActivity.this, KEY, MainActivity.this); bp.initialize(); boolean isSubscriptionUpdateSupported = bp.isSubscriptionUpdateSupported(); if(isSubscriptionUpdateSupported) { bp.subscribe(MainActivity.this, "item"); }else { Log.e("Doesn't support", "Error"); } } }); 

But on isSubscriptionUpdateSupported throws a NullPointerException. What am I doing wrong?

UPD

Process: me.pokerhelper, PID: 28178 java.lang.NullPointerException: Attempt to invoke interface method 'int com.android.vending.billing.IInAppBillingService.isBillingSupported (int, java.lang. a null object reference at com. anjlab View.java:5610) at android.view.View $ PerformClick.run (View.java:22265) at android.os.Handler.handleCallback (Handler.java:751) at android.os.Handler.dispatchMessage (Handler.java : 95) at android.os.Looper.loop (Looper.java:15) at android.app.ActivityThread.main (ActivityThread.java:6077) at java.lang.reflect.Method.invoke (Native Method) at com. android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:866) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:756)

UPD

I did this:

 bp = new BillingProcessor (MainActivity.this, KEY, MainActivity.this); unlock_full_version.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { buy(); } }); ... public void buy(){ bp.subscribe(MainActivity.this, "android.test.purchase"); } 

But now the purchase is made when you first start the application without pressing the button: D

  • Add error to the question - eugeneek
  • @eugeneek added, though a little crooked - Nikita Shavrin

2 answers 2

The library in the box did not have time to create a copy of the class to work with the Service, the MB and the service itself has not yet started. This call has a special callback, @Override public void onBillingInitialized() { /* * Called when BillingProcessor was initialized and it's ready to purchase */ }

which signals that Handler is ready to work, try to transfer there. But in general, the initialization of such a heavy operation is necessary in advance on OnCreate for example, and then manage all operations through the Controllers.

Also make sure that your AIDL interface is configured, there are quite working options in Google samples.

  • And do not tell me how to do it right? - Nikita Shavrin
  • And then when bp = BillingProcessor.newBillingProcessor(MainActivity.this, KEY, MainActivity.this); bp.initialize(); bp = BillingProcessor.newBillingProcessor(MainActivity.this, KEY, MainActivity.this); bp.initialize(); in oncreate, it doesn't help vseravno - Nikita Shavrin
  • Do you have a aidl folder in the project, is the interface added? CallBack catch who in the answer, prologuyte look at the error - Shwarz Andrei
  • I don’t have such a daddy even 0_o Found it, but it’s empty - Nikita Shavrin
 bp = BillingProcessor.newBillingProcessor(this, KEY, this); unlock_full_version.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { bp.initialize(); buy(); } }); 

This is the code that worked.