Android Question Looks Like a Bug with Menu and Rapid Debug

GuyBooth

Active Member
Licensed User
Longtime User
I am using a simple menu using the following code, but sometimes the Menu seems to flicker (perhaps if I hold the "click" a little too long?) and the response becomes -3.
So the first problem is How does that happen? -3 is not a choice as far as I know.

I then tried to work around it by adding a loop to tell the user to select again, the final code is shown below:

B4X:
Dim lstNPMenu As List
Dim lMenuChoice As Long
' For the menu loop to start
            lMenuChoice = -1
            ' Set up the menu selections
            lstNPMenu.Add("Cancel")
            lstNPMenu.Add("Play Now")
            lstNPMenu.Add("Set TrackStop " & TMM.iif(TrackRecord.TrackStop, "Off", "On"))
            lstNPMenu.Add("Move")
            lstNPMenu.Add("Move to Start of Queue")
            lstNPMenu.Add("Move to End of Queue")
            lstNPMenu.Add("Remove from Queue")
            ' Menu loop:
            Do While Not("0123456".Contains(lMenuChoice))
                ' Open dialogue to choose an action
                lMenuChoice = InputList(lstNPMenu,"Options",0)
                ' Respond to chosen selection
                Select lMenuChoice
                    Case 0
                        ' Cancel
                    Case 1
                          Code
                    Case 2
                          Code
                    Case 3
                        Code
                    Case 4
                        Code
                    Case 5
                        Code
                    Case 6
                        Code
                    Case Else
                        ToastMessageShow("System Returned an Invalid Entry" & CRLF & "Please Choose Again.",False)
                        End If
                End Select
            Loop

After I ran into this problem I tried putting the menu into a loop, so if the -3 was returned the user would be asked to re-input a response. This leads to the menu freezing and the following log:

B4X:
java.lang.NullPointerException
     at anywheresoftware.b4a.Msgbox$DialogResponse.onClick(Msgbox.java:118)
    at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:934)
    at android.widget.AdapterView.performItemClick(AdapterView.java:298)
    at android.widget.AbsListView.performItemClick(AbsListView.java:1280)
    at android.widget.AbsListView$PerformClick.run(AbsListView.java:3067)
    at android.widget.AbsListView$1.run(AbsListView.java:3968)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4895)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
    at dalvik.system.NativeStart.main(Native Method)

Has anyone run into a problem like this with the menu? Would appreciate some help.
 
Last edited:

eps

Expert
Licensed User
Longtime User
I think, from the small snippet of code that you've alluded to that you are approaching this from the wrong angle, but it's a little tough to work out going on what you've given us.

You seem to be looping through the menu selections, but surely you process a menu selection using a Click Event or Keypress and process this..?

The DoWhile loop looks all wrong for Android, have you read the process lifecycle document? It seems like you are approaching this from a traditional programming background.
 
Upvote 0

GuyBooth

Active Member
Licensed User
Longtime User
I think, from the small snippet of code that you've alluded to that you are approaching this from the wrong angle, but it's a little tough to work out going on what you've given us.

You seem to be looping through the menu selections, but surely you process a menu selection using a Click Event or Keypress and process this..?

The DoWhile loop looks all wrong for Android, have you read the process lifecycle document? It seems like you are approaching this from a traditional programming background.

Yes I've read the documents you refer to.
To clarify - this is a "pop-up" menu, not the one at the top (or bottom) of the screen. Hence it is not processed using Events, but using the result of the menu choice as I have seen in several examples on this site and in documentation.

Also, as I previously stated, the loop was only added after I ran into the problem of the -3 being returned as a result of the click. The basic, root problem is that the -3 should never show up in the first place. How can I be seeing a result that is not one of the choices? The choices are 0 to 6.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Try this:
B4X:
Dim lstNPMenu As List
Dim lMenuChoice As Int
 
 
lstNPMenu.Initialize
lstNPMenu.Add("Cancel")
lstNPMenu.Add("Play Now")
lstNPMenu.Add("Set TrackStop ")
lstNPMenu.Add("Move")
lstNPMenu.Add("Move to Start of Queue")
lstNPMenu.Add("Move to End of Queue")
lstNPMenu.Add("Remove from Queue")
lstNPMenu.Add("Something else")
' Open dialogue to choose an action
lMenuChoice = InputList(lstNPMenu,"Options",0)
'Respond to chosen selection
Select lMenuChoice
Case 0
  Msgbox("You selected Cancel","")
Case 1
  Msgbox("You selected Play Now","")
Case 2
  Msgbox("You selected Set TrackStop ","")
Case 3
  Msgbox("You selected Move","")
Case 4
  Msgbox("You selected Move to Start of Queue","")
Case 5
Msgbox("You selected Move To End of Queue","")
Case 6
  Msgbox("You selected Remove from Queue","")
Case Else
Msgbox("You selected something else","")
End Select
 
Upvote 0

GuyBooth

Active Member
Licensed User
Longtime User
Try this:
B4X:
Dim lstNPMenu As List
Dim lMenuChoice As Int
 
lstNPMenu.Initialize
lstNPMenu.Add("Cancel")
lstNPMenu.Add("Play Now")
lstNPMenu.Add("Set TrackStop ")
lstNPMenu.Add("Move")
lstNPMenu.Add("Move to Start of Queue")
lstNPMenu.Add("Move to End of Queue")
lstNPMenu.Add("Remove from Queue")
lstNPMenu.Add("Something else")
' Open dialogue to choose an action
lMenuChoice = InputList(lstNPMenu,"Options",0)
'Respond to chosen selection
Select lMenuChoice
Case 0
  Msgbox("You selected Cancel","")
Case 1
  Msgbox("You selected Play Now","")
Case 2
  Msgbox("You selected Set TrackStop ","")
Case 3
  Msgbox("You selected Move","")
Case 4
  Msgbox("You selected Move to Start of Queue","")
Case 5
Msgbox("You selected Move To End of Queue","")
Case 6
  Msgbox("You selected Remove from Queue","")
Case Else
''Msgbox("You selected something else - ","")
Msgbox("You selected something else - MenuChoice " &  lMenuChoice,"")
End Select

Mahares, this is pretty much what I had to begin with, but to prove a point I took out all my code and substituted your code. I am triggering it from the LongClick of a CustomListView, hence the "Sub NowPlaying_ItemLongClick" line in the log below. Note I did change the final msgbox to get me some more information.
It works fine for a few times, and then I get "You selected something else - MenuChoice -3" as a response, at which point the menu freezes and I get the following log:
B4X:
Sub NowPlaying_ItemLongClick
java.lang.NullPointerException
    at anywheresoftware.b4a.Msgbox$DialogResponse.onClick(Msgbox.java:118)
    at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:934)
    at android.widget.AdapterView.performItemClick(AdapterView.java:298)
    at android.widget.AbsListView.performItemClick(AbsListView.java:1280)
    at android.widget.AbsListView$PerformClick.run(AbsListView.java:3067)
    at android.widget.AbsListView$1.run(AbsListView.java:3968)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4895)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
    at dalvik.system.NativeStart.main(Native Method)

What I get from all this so far is that my original code is not the problem, and I'm wondering if there is a problem with it being called from the CustomListView Item LongClick. Strange thing is that I was running this code a month or so back in a previous version without this problem - hence my question as to whether there is a bug, possibly introduced by B4A version 3.00.
Will test some more ...

Later that same night ....
I have run the same code from a menu, as opposed to the LongClick trigger. No change in the results.
I ran the same code in a totally empty environment, the activity only holds a button. I could not make it fail with this. So something in my whole app is causing this - memory issues? Something else?
 
Last edited:
Upvote 0

GuyBooth

Active Member
Licensed User
Longtime User
-3 is the cancel operation.

mc73, I have now seen -3 come up quite consistently - but I don't understand what it is. You say it is the "cancel operation" - but what is doing the cancelling, and why? I'm seeing it when a legitimate choice is clicked...
 
Upvote 0

GuyBooth

Active Member
Licensed User
Longtime User
OK - I stopped using the Rapid Debugger and the problem SO FAR has disappeared.
Just need to find out where to report the bug ...

Thanks for everyone's help! Hopefully I won't be back tomorrow morning to say it's not working again!
 
Last edited:
  • Like
Reactions: eps
Upvote 0

nwhitfield

Active Member
Licensed User
Longtime User
Managed to find this thread; I'm seeing exactly the same thing happening in my code with an InputList, but I'm not using the RapidDebugger; I end up with the 'application has stopped' message.

I can, at least, now make this happen repeatedly.

I have a function that fetches data from a remote server, and builds a display. Within that, I use DoEvents to allow a ProgressDialog to update (once every five iterations).

If, while that's still happening, I tap the view that launches the InputList, then it immediately returns -3, even though no item has been selected.

If I then tap an item, it highlights, and sits there, doing nothing.

Tap again, and the app will suddenly quit.

I get the same error:

B4X:
E/AndroidRuntime(14330): FATAL EXCEPTION: main
E/AndroidRuntime(14330): java.lang.NullPointerException
E/AndroidRuntime(14330):    at anywheresoftware.b4a.Msgbox$DialogResponse.onClick(Msgbox.java:118)
E/AndroidRuntime(14330):    at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:941)
E/AndroidRuntime(14330):    at android.widget.AdapterView.performItemClick(AdapterView.java:298)
E/AndroidRuntime(14330):    at android.widget.AbsListView.performItemClick(AbsListView.java:1100)
E/AndroidRuntime(14330):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:2788)
E/AndroidRuntime(14330):    at android.widget.AbsListView$1.run(AbsListView.java:3463)
E/AndroidRuntime(14330):    at android.os.Handler.handleCallback(Handler.java:730)
E/AndroidRuntime(14330):    at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(14330):    at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(14330):    at android.app.ActivityThread.main(ActivityThread.java:5103)
E/AndroidRuntime(14330):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(14330):    at java.lang.reflect.Method.invoke(Method.java:525)
E/AndroidRuntime(14330):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
E/AndroidRuntime(14330):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
E/AndroidRuntime(14330):    at dalvik.system.NativeStart.main(Native Method)

If I allow the main task to finish, at which point it removes the ProgressDialog, then the InputList works flawlessly every time.

Nigel.
 
Upvote 0

nwhitfield

Active Member
Licensed User
Longtime User
The background loop, or just the bit of code where I'm calling InputList? The background loop is pretty long, and works fine on its own
 
Upvote 0

nwhitfield

Active Member
Licensed User
Longtime User
So the solution is really to shove all my processing from that loop into a separate thread somehow?

The main reason for using DoEvents is simply so that, as it takes a few seconds to process the data sometimes, I'd like a progress display to update.

DoEvents is a simply way to allow the standard ProgressDialog to update. But I suppose instead I could use a custom animation, updated from within the loop.
 
Upvote 0

nwhitfield

Active Member
Licensed User
Longtime User
It's working through a JSON array retrieved from the server, which can have around 120 or so elements (representing members of a site who are online); for each one, it's checking in a database for a thumbnail image, and adding that, if found, to a panel with text info from the JSON member list, then adding it to a CustomListView. There's also another view being created, which has the thumbnails in a mosaic instead, so the user can switch between the two.

I think the main cause of the delay, however, is that I update a 'lastused' timestamp for each thumbnail in the database, which is used to control how long they are cached for. Perhaps I should ditch that step.
 
Upvote 0

nwhitfield

Active Member
Licensed User
Longtime User
Just talking it through has helped wonderfully, thanks very much!

I went back and looked at the docs, and where I had a line in a loop that flagged thumbnails as used with an update to the database using SQL.ExecNonQuery, I've switched that to AddNonQueryToBatch, and executed the batch when the loop is finished.

Removed the DoEvents from the loop too, and everything is much, much faster.

Problem solved; it just wasn't in the place I was originally looking for it.
 
Upvote 0
Top