Android Question [Solved][B4XTable] Crash in ResultSet if click on "Recents" phone button

GabrielM

Member
Licensed User
Longtime User
I use one sub with code attached below that suppose to fill a list with a B4XTable rows.
It works great, but if accidentally I have clicked on "Recents" button on the phone while the code is in the "Do While rs.NextRow " loop the app will crash with the error listed below.

Not sure what would be the recommended approach: move code to a Service or deal with it in B4XPage_CloseRequest sub ?


B4X:
Sub Class_Globals
    Public my_list As List
    Public my_B4XTABLE As B4XTable
End Sub

Public Sub ExportTableToLIST
    my_list.Initialize
    
    Dim rs As ResultSet = my_B4XTABLE.sql1.ExecQuery("SELECT * FROM data")

    Do While rs.NextRow            ' <<< Error occurred on line: This line             
        Dim row(my_B4XTABLE.Columns.Size) As String
        For i = 0 To my_B4XTABLE.Columns.Size - 1
            Dim c As B4XTableColumn = my_B4XTABLE.Columns.Get(i)
            row(i) = rs.GetString(c.SQLID)
        Next
        my_list.Add(row)
    Loop
    rs.Close
End Sub

And this is the error I got in logs:

B4X:
** Activity (main) Pause event (activity is not paused). **
Error occurred on line: 1445 (B4X_Page_Tests)
java.lang.Exception: array not expected...
java.lang.RuntimeException: Unable to create service com.mycompany.ptest.starter: java.lang.RuntimeException: java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.OutputStream.write(byte[])' on a null object reference
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:4204)
    at android.app.ActivityThread.access$1500(ActivityThread.java:237)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:223)
    at android.app.ActivityThread.main(ActivityThread.java:7656)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.RuntimeException: java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.OutputStream.write(byte[])' on a null object reference
    at anywheresoftware.b4a.shell.Shell.virtualAssets(Shell.java:164)
    at anywheresoftware.b4a.shell.Shell.start(Shell.java:102)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:92)
    at com.mycompany.ptest.starter.onCreate(starter.java:34)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:4192)
    ... 8 more
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.OutputStream.write(byte[])' on a null object reference
    at anywheresoftware.b4a.shell.ShellConnector.sendControlMessage(ShellConnector.java:61)
    at anywheresoftware.b4a.shell.Shell.virtualAssets(Shell.java:124)
    ... 12 more
 

GabrielM

Member
Licensed User
Longtime User
Yes, in release mode it was doing it.
I have switched to B4XPages now, and issue does not happening so far I have tested.
Much appreciated.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…