Android Question In-App Billing error: a null object reference

androh

Member
Licensed User
Longtime User
I've a problem that I can not fix.
My application is always running background. Billing manager is in Starter Service.
If I call manager.GetOwnedProducts while Google Play Store stopped (self-update or change device language etc.), my application crashes.

I find a same error here https://github.com/googlesamples/android-play-billing/issues/45#issuecomment-324466519

And here a solution https://github.com/googlesamples/android-play-billing/issues/45#issuecomment-328961916

How can I register a event for onBillingServiceDisconnected() for BillingManager?

B4X:
java.lang.NullPointerException:
 
  at anywheresoftware.b4a.objects.IbHelper.queryPurchases (IbHelper.java:836)
 
  at anywheresoftware.b4a.objects.IbHelper.queryInventory (IbHelper.java:544)
 
  at anywheresoftware.b4a.objects.IbHelper.queryInventory (IbHelper.java:523)
 
  at anywheresoftware.b4a.objects.IbHelper$3.run (IbHelper.java:616)
 
  at java.lang.Thread.run (Thread.java:764)
 
Last edited:

androh

Member
Licensed User
Longtime User
I found a solution

B4X:
Sub Service_Create
 
   InitBillMan
 
End Sub

Sub CheckProducts

   Dim r As Reflector
   r.Target=BillingManager
   r.Target=r.GetField("helper")
   r.Target=r.GetField("mService")
          
   If Not(r.IsNull) Then         
       BillingManager.GetOwnedProducts
   Else
       InitBillMan
   End If

End Sub

Private Sub InitBillMan
 
   BillingManager.Initialize("BillMan", BillingKey)
 

   Wait For BillMan_BillingSupported (Supported As Boolean, Message As String)
   If Supported Then
       BillingManager.GetOwnedProducts
   End If

End Sub
 
Last edited:
Upvote 0
D

Deleted member 103

Guest
Hi @androh ,

I have exactly the same error.
One thing I do not understand in your code, where / when is the SUB CheckProducts running?
 
Upvote 0

androh

Member
Licensed User
Longtime User
Hi Filippo,
You can run CheckProducts when you want to get owned products.
Therefore you can change your code "BillingManager.GetOwnedProducts" with "CheckProducts".
CheckProducts sub will run "BillingManager.GetOwnedProducts" safely.
 
Upvote 0
Top