Android Question Strange error

ddk1

Member
Licensed User
I'm getting a strange error doing something fairly basic. It has worked fine in the past though its been some time since I used this feature.

Basically a customlistview has some checkboxes. For each one checked, a Type variable from the 'All' list gets copied to the 'Selected' list. It then calls another activity that uses the 'Selected' list to do stuff.
If the number of items added to 'Selected' list=1, all is fine. If >1, then I get an error on line 'If Main.glstSelectedLists.Size = 1 Then'

Error:
StartActivity(UserList)
** Activity (main) Pause, UserClosed = false **
** Activity (userlist) Create, isFirst = true **
UserList_Activity_Create
Main.glstSelectedLists.Size=2
Error occurred on line: 68 (UserList)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at com.QuikList.userlist$ResumableSub_Activity_Create.resume(userlist.java:471)
at com.QuikList.userlist._activity_create(userlist.java:408)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)

B4X:
--- Main ---------------------------
Sub Process_Globals
    Dim glstSelectedLists As List
    Dim glstAllLists As List      
    Type MainListRow(ListNo As Int, ListName As String, ListAbbr As String, DelSrcWhenPicked As Boolean, MasterList As String, R As Int, G As Int, B As Int, HighlightCnt As Boolean, MasterKbd As Boolean, MasterImm As Boolean)  

Sub mnuLoadMains_Click
    Dim intCnt1 As Int
    Dim pnl As Panel
    Dim lbl As Label
    Dim chk As CheckBox
    Dim mlr As MainListRow
   
    glstSelectedLists.Clear
    For intCnt1 = 0 To clvMain.GetSize-1
        pnl = clvMain.GetPanel(intCnt1)
        chk = pnl.GetView(0)
        If chk.Checked Then
            lbl = pnl.GetView(1)
            mlr = glstAllLists.Get(lbl.Tag)
            glstSelectedLists.Add(mlr)
        End If
    Next

    If glstSelectedLists.Size > 0 Then
        Log("StartActivity(UserList)")      
        StartActivity(UserList)
    End If
   
End Sub

-- UserList ---------------------
Sub Activity_Create(FirstTime As Boolean)

      Dim mlrList As MainListRow

      Log("UserList_Activity_Create")
67  Log("Main.glstSelectedLists.Size=" & Main.glstSelectedLists.Size)
68  If Main.glstSelectedLists.Size = 1 Then

Line numbers 67 & 68 above are just to demonstrate where the fail is happening.
So line 67 is fine using Main.glstSelectedLists.Size which = 2
but line 68 gives an error testing if Main.glstSelectedLists.Size > 1 BUT ONLY if Main.glstSelectedLists.Size is actually > 1

What gives?
B4A 11.00. Java 11
 
Last edited:

ddk1

Member
Licensed User
I don't want to spend time converting a (was) perfectly working app. That said....its not working now :)
Just run the app. It should create two entries in the CLV. Tick one then tap the eye icon. Works fine. Tick two then tap eye icon, Fails.
 

Attachments

  • QuikList.zip
    316 KB · Views: 122
Upvote 0

ddk1

Member
Licensed User
How odd. Same with Release mode.
I just connected an unrelated mobile in USB debugging mode, compiled in Release mode. Got same error.
Logs seem the same, or do I need to use LogCat?

Logger connected to: -------------
--------- beginning of main
--------- beginning of system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
27/07/21 20:53:04.860 ---------------------------------------------
** Activity (main) Resume **
** Service (starter) Destroy (ignored)**
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (activity_permissionresult)
sending message to waiting queue (activity_permissionresult)
running waiting messages (2)
Activity_PermissionResult
Activity_PermissionResult
** Activity (main) Resume **
*** Service (reminderservice) Create ***
** Service (reminderservice) Start **
mnuLoadMains_Click: glstSelectedLists.Size=2
StartActivity(UserList)
** Activity (main) Pause, UserClosed = false **
** Activity (userlist) Create, isFirst = true **
UserList_Activity_Create
Main.glstSelectedLists.Size=2
2
userlist$ResumableSub_Activity_Createresume (java line: 460)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at com.QuikList.userlist$ResumableSub_Activity_Create.resume(userlist.java:460)
at com.QuikList.userlist._activity_create(userlist.java:404)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at com.QuikList.userlist.afterFirstLayout(userlist.java:105)
at com.QuikList.userlist.access$000(userlist.java:17)
at com.QuikList.userlist$WaitForLayout.run(userlist.java:83)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7948)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
--------- beginning of crash
 
Upvote 0

ddk1

Member
Licensed User
You're absolutely right, and yes, that area is something I changed some weeks ago leading to the missing Initialize. And I've never pressed the eye button since then.
Before posting, I did compile it in debug mode and step through the code to find the problem and it failed at the line I said, which is BEFORE the line you have pointed out. So that did make it a bit tricky to spot.......
Still, my bad. Many thanks.
 
Upvote 0
Top