Android Question Error (NullPointerException) when calling LaunchBillingFlow (GooglePlayBilling Libary)

Pascal Hamm

Member
Licensed User
Hello All,
I am currently reprogramming my app to the new GooglePlayBilling Libary.
So far everything has worked fine, but when I now want to buy a subscription, it comes within LaunchBillingFlow to an error.

I have already read all the entries about this, but unfortunately no one has had this problem yet.

Also in the manifest I added the entry "CreateResourceFromFile(Macro, GooglePlayBilling.GooglePlayBilling)"

The problem occurs in my sub "BuyProduct", from the logs you can see that "LaunchBillingFlow" is causing the problems.

Maybe someone of you has another idea.

Attached is the code snippet and the logs:

B4X:
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
'GooglePlayBilling Code
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX

'Abfrage des aktuellen Status vom Google Server über vorhandene InApp-Käufe (Überprüfe, ob ein Abo vorhanden ist)
Private Sub RestorePurchases
    Wait For (billing.ConnectIfNeeded) Billing_Connected (Result As BillingResult)
    Log("------------------GooglePlayBilling------------------")
    If Result.IsSuccess Then
        Wait For (billing.QueryPurchases("subs")) Billing_PurchasesQueryCompleted (Result As BillingResult, Purchases As List)
        Log("Abfrage abgeschlossen: " & Result.IsSuccess)
        If Result.IsSuccess Then
            Log("TEST" & Purchases & "Ende")
            For Each p As Purchase In Purchases
                If p.Sku = ADS_SDK_ID Then
                    Log("Vorhandene Purchases (Abos): " & p.Sku)
                    HandleAdsPurchase(p)
                End If
            Next
        Else
            Log("Fehler: Kein Purchase Success (P1)")
            Log("Aktiviert: Staumelder MOBILE Free")
            SetStatusAppVersion("free")
        End If
    End If
End Sub

'Wenn ein Abo vorhanden ist, dan wird es hier freigeschalten
Private Sub HandleAdsPurchase (p As Purchase)
    If p.PurchaseState <> p.STATE_PURCHASED Then Return
    'Verify the purchase signature.
    'This cannot be done with the test id.
    If p.Sku.StartsWith("staumelder_mobile_abo_1") = False And billing.VerifyPurchase(p, BILLING_KEY) = False Then
        Log("Invalid purchase (P2)")
        Return
    End If
    If p.IsAcknowledged = False Then
        'we either acknowledge the product or consume it.
        Wait For (billing.AcknowledgePurchase(p.PurchaseToken, "")) Billing_AcknowledgeCompleted (Result As BillingResult)
        Log("Acknowledged: " & Result.IsSuccess)
    End If
    
    'Staumelder MOBILE Pro aktivieren
    Log("Aktiviert: Staumelder MOBILE Pro")
    SetStatusAppVersion("pro")

End Sub


Sub billing_PurchasesUpdated (Result As BillingResult, Purchases As List)
    'This event will be raised when the status of one or more of the purchases has changed.
    'It will usually happen as a result of calling LaunchBillingFlow however it can be called in other cases as well.
    If Result.IsSuccess Then
        For Each p As Purchase In Purchases
            If p.Sku = ADS_SDK_ID Then
                HandleAdsPurchase(p)
            Else
                Log("Unerwartetes Produt")
                Log("Aktiviert: Staumelder MOBILE Free")
                SetStatusAppVersion("free")
            End If
        Next
    End If
End Sub


Sub BuyProduct
    'make sure that the store service is connected
    Wait For (billing.ConnectIfNeeded) Billing_Connected (Result As BillingResult)
    If Result.IsSuccess Then
        'get the sku details
        Log("Abo wird nun gekauft (BuyProduct)")
        Dim sf As Object = billing.QuerySkuDetails("subs", Array(ADS_SDK_ID))
        Log("__1__")
        Wait For (sf) Billing_SkuQueryCompleted (Result As BillingResult, SkuDetails As List)
        Log("__2__")
        If Result.IsSuccess And SkuDetails.Size = 1 Then
            Log("__3__")
            Log(SkuDetails)
            Result = billing.LaunchBillingFlow(SkuDetails.Get(0))
            Log("__4__")
            If Result.IsSuccess Then 
                Log("Abo wurde gekauft")
                Return
            End If
        End If
    End If
    ToastMessageShow("Fehler beim Kaufprozess, bitte versuchen Sie es später noch einmal", True)
End Sub


Log:

------------------GooglePlayBilling------------------
Abfrage abgeschlossen: true
TEST(ArrayList) []Ende
Abo wird nun gekauft (BuyProduct)
__1__
__2__
__3__
(ArrayList) [SkuDetails: {"productId":"staumelder_mobile_abo_1","type":"subs","title":"Staumelder MOBILE Pro (Staumelder MOBILE)","name":"Staumelder MOBILE Pro","price":"11,99 €","price_amount_micros":11990000,"price_currency_code":"EUR","description":"Upgrade auf Staumelder MOBILE Pro. Bietet deutlich mehr Funktionen !","subscriptionPeriod":"P1Y","freeTrialPeriod":"P1W","skuDetailsToken":"AEuhp4XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}]
starter$ResumableSub_BuyProductresume (java line: 256)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get()' on a null object reference
at anywheresoftware.b4a.objects.BillingClientWrapper.LaunchBillingFlow(BillingClientWrapper.java:248)
at de.staumelder24.staumeldermobile.starter$ResumableSub_BuyProduct.resume(starter.java:256)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:207)
at anywheresoftware.b4a.BA$2.run(BA.java:387)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:7876)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
starter$ResumableSub_BuyProductresume (java line: 256)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get()' on a null object reference
at anywheresoftware.b4a.objects.BillingClientWrapper.LaunchBillingFlow(BillingClientWrapper.java:248)
at de.staumelder24.staumeldermobile.starter$ResumableSub_BuyProduct.resume(starter.java:256)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:207)
at anywheresoftware.b4a.BA$2.run(BA.java:387)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:7876)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
 
Top