Android Question [Solved] - Null pointer error with Msgbox2Async

rleiman

Well-Known Member
Licensed User
Longtime User
Greetings,

This example coding is from the community search for Msgbox2Async. When I run an app with the code inserted, the app crashes with a null pointer exception.

Can you tell me what the example coding I found is missing?

Thanks.


This code results in a NoPointerException:
Msgbox2Async("Question?", "Title", "Yes", "Cancel", "No", Null, False)
Wait For Msgbox_Result (Result As Int)
If Result = DialogResponse.POSITIVE Then
    '...
End If

servicemodule$ResumableSub_Service_Createresume (java line: 594)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get()' on a null object reference
    at anywheresoftware.b4a.keywords.Common.Msgbox2Async(Common.java:486)
    at b4a.example.servicemodule$ResumableSub_Service_Create.resume(servicemodule.java:594)
    at b4a.example.servicemodule._service_create(servicemodule.java:534)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at b4a.example.servicemodule.onCreate(servicemodule.java:56)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:4577)
    at android.app.ActivityThread.access$1700(ActivityThread.java:301)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2137)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:246)
    at android.app.ActivityThread.main(ActivityThread.java:8425)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:596)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
 

William Lancee

Well-Known Member
Licensed User
Longtime User
A couple of things wrong...

B4X:
Wait For (xui.Msgbox2Async("Question?", "Title", "Yes", "Cancel", "No", Null)) Msgbox_Result (Result As Int)
If Result = xui.DialogResponse_Positive Then
    '...
End If
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Thanks for all the replies.

I moved the coding from post number 2 to my B4XMainPage module and all is well now. I originally used the Msgbox2Async coding from the sample coding and that also crashed the app but as soon as I changed it to xui.Msgbox2Async, it solved the crashing.

Maybe the documentation in the search needs to be updated?
 
Upvote 0
Top