Android Question java.lang.NullPointerException error when calling function

nima66

Member
Is it possible that in Android 12 and above, when we leave the app for 5 minutes and return to the app, the module code cannot be recognized?
This happened for a variable from the list on some phones and I fixed it.
I store user errors in the server database.
Now the problem is that sometimes when some users temporarily leave the app to pay and return to the app after paying, one of the functions in the module code is called and gives an error.
While according to the test, no error occurs even if the input to this function is empty.
Now I suspect that maybe it doesn't recognize the module code at all.

B4X:
Private Sub poolakey_consumeSucceed
    If purchaseInfo_productId.Trim.Length>0 Then
        Product_ProductId=purchaseInfo_productId

        Private lst As List
        lst.Initialize
        lst.Add(func.set_string(Product_ProductId)) << The error occurs at this line.
        .
        .
        .
        .
 

nima66

Member
Switch to B4XPages.
I have 15 activities with a total of about 10,000 lines of code.
I shouldn't put all the code in one class.
So if I reuse the module code, what's the difference from the current situation?
It is possible that after 5 minutes of the application being in the background, the module code will not be recognized again
Am I right?

What is the overall reason for this problem that some users are experiencing?
 
Upvote 0

nima66

Member
No. The problem is somewhere else. The only type of modules that are destroyed while the app is in the background is service modules.
According to the error logged on the server
It claims that the input to a function in the module code is NULL.
While I gave the same function a NULL value for testing, it did not give an error.
It displays this error:

B4X:
java.lang.NullPointerException: Attempt to read from field 'idea.game.management.func idea.game.management.chg._func' on a null object reference in method 'java.lang.String idea.game.management.chg._poolakey_consumesucceed()'
    at idea.game.management.chg._poolakey_consumesucceed(chg.java:1381)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
    at com.poolakey.wrapper.PoolakeyWrapper$consumeProduct$1$1.invoke(PoolakeyWrapper.kt:161)
    at com.poolakey.wrapper.PoolakeyWrapper$consumeProduct$1$1.invoke(PoolakeyWrapper.kt:160)
    at ir.cafebazaar.poolakey.billing.consume.ConsumeFunction$function$$inlined$with$lambda$2.invoke(ConsumeFunction.kt:37)
    at ir.cafebazaar.poolakey.billing.consume.ConsumeFunction$function$$inlined$with$lambda$2.invoke(ConsumeFunction.kt:14)
    at ir.cafebazaar.poolakey.thread.MainThread.handleMessage(MainThread.kt:11)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:230)
    at android.os.Looper.loop(Looper.java:319)
    at android.app.ActivityThread.main(ActivityThread.java:8919)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)

When executing the following code it gives the above error :

B4X:
Private Sub poolakey_consumeSucceed
    If purchaseInfo_productId.Trim.Length>0 Then
        Product_ProductId=purchaseInfo_productId

        Private lst As List
        lst.Initialize
        lst.Add(func.set_string(Product_ProductId)) << The error occurs at this line.
        .
        .
        .
        .
 
Upvote 0

nima66

Member
func is Null or not initialized.
func is a Code Module.
Its functions are used constantly during the execution of the application. Only sometimes on some devices when the application is not running for a while and we return to the application, such an error occurs!

For the set_string function, it doesn't give an error even if the input is NULL.
That's why I'm surprised
 
Upvote 0

david7374

Member
func is a Code Module.
Its functions are used constantly during the execution of the application. Only sometimes on some devices when the application is not running for a while and we return to the application, such an error occurs!

For the set_string function, it doesn't give an error even if the input is NULL.
That's why I'm surprised
Hi,
Try this way:
B4X:
Private Sub poolakey_consumeSucceed
     CallSubDelayed(Me, "cafebazaarsucceed")
End Sub

Sub cafebazaarsucceed
    If purchaseInfo_productId.Trim.Length>0 Then
        Product_ProductId=purchaseInfo_productId

        Private lst As List
        lst.Initialize
        lst.Add(func.set_string(Product_ProductId)) << The error occurs at this line.
        .
        .
        .
        .
End Sub
 
Upvote 0

nima66

Member
Hi,
Try this way:
B4X:
Private Sub poolakey_consumeSucceed
     CallSubDelayed(Me, "cafebazaarsucceed")
End Sub

Sub cafebazaarsucceed
    If purchaseInfo_productId.Trim.Length>0 Then
        Product_ProductId=purchaseInfo_productId

        Private lst As List
        lst.Initialize
        lst.Add(func.set_string(Product_ProductId)) << The error occurs at this line.
        .
        .
        .
        .
End Sub
Thank you
I'll try
You know cafebazaar !
 
Upvote 0
Top