Android Question [Solved: Initialize class From Starter to MAIN] xui.msgboxasyn return error java.lang.NullPointerException

netsistemas

Active Member
Licensed User
Longtime User
I have transformed all my modules to classes with no problems.
But in a class I have a

xui.MsgboxAsync

which returns the following error:

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get()' on a null object reference



In a mini project that I was testing, it does work, so I don't know how to deal with the problem. Thanks.
The reason for changing it from module to classes is to be able to better capture the waitfor and recommendations in this forum.
 

agraham

Expert
Licensed User
Longtime User
Code? Full error text with stack trace?

EDIT: Judging by your previous post of message box in a code module I suspect that you are stacking message box one after another and something is incorrect. I've looked at the Java code in B4A for message boxes and the only WeakReference.get() I can find id concerned with managing message box instances.
 
Last edited:
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
Error occurred on line: 811 (clsConexion)
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 anywheresoftware.b4a.objects.B4XViewWrapper$XUI.MsgboxAsync(B4XViewWrapper.java:786)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:7506)
at android.view.View.performClickInternal(View.java:7483)
at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
at android.view.View$PerformClick.run(View.java:29335)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

-----

I think the problem is that there is no 'PAGE' where to associate or link the XUI.MsgboxAsync (I don't know how to explain it).

This has led me to transfer my function to B4XMainPage and that is how it is solved, but it would be interesting to know what happens in this case in which a module has a class, which launches XUI.MsgBoxAsyn

Solution:

B4X:
PUBLIC Sub MiMsgBoxCsBuilder(M1 As String, M2 As String)
   
    B4XPages.MainPage.MiMsgBoxCsBuilder(M1,M2)


Return

And in B4xMainPage:

B4X:
PUBLIC Sub MiMsgBoxCsBuilder(M1 As String, M2 As String)

    Try
    
        
        xui.MsgboxAsync (m1,m2)
            
    Catch
        Log(LastException)
        
        'XUI.MsgboxAsync(M1,M2)
    End Try
    

End Sub
 
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
Fixed. Thinking about the difference between the demo project and mine, I have seen that mine initialized the classes in the STARTER module.
I have transferred that code to the MAIN Module, inside the Activity_Create and solved.
Thanks agraham, by pointing your comment out to me, it made me think differently.

B4X:
Sub Activity_Create(FirstTime As Boolean)

'Main Module in b4x pages

    'Este código lo traigo del STARTER, pues algo raro sucede que los MSGBOX no funcionan.
    '(code from starter to here.)
    modB4A.ICLSINI.Initialize
    modB4A.iclsConexion.Initialize
    modB4A.IclsSqls.Initialize
    modB4A.IclsSqls.iWs.Initialize
    modB4A.IclsFTP.Initialize
 
Upvote 0

calloatti

Member
Licensed User
I run into the same problem (also a B4XPages project) using RuntimePermissions.CheckAndRequest in Starter.Service_Create, also had to move it to Main.Activity_Create

Probably there are one or more UI objects that are needed and are only created in Main. (Probably Activity? who knows)

TLDR: Starter.Service_Create may be too early sometimes for some things.
 
Upvote 0
Top