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

Discussion in 'Android Questions' started by androh, Feb 23, 2018.

Tags:
  1. androh

    androh Member Licensed 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?

    Code:
    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: Feb 23, 2018
  2. androh

    androh Member Licensed User

    I found a solution

    Code:
    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: Feb 24, 2018
    Filippo likes this.
  3. Filippo

    Filippo Expert Licensed User

    Hi @androh ,

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

    androh Member Licensed 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.
     
    Filippo likes this.
  5. Filippo

    Filippo Expert Licensed User

    Alright, thank you! :)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice