Uncaught TypeError only on Android devices

I’m getting “Uncaught TypeError” on my app when running on Android (created with Voltbuilder). I do not get any errors running on iOS or desktop browser. It seems to be around the 2D arrays I use in the app, but I’m finding it very difficult to track down the problem.

Has anyone had a similar issue with Android build having Uncaught TypeErrors while it runs fine elsewhere? I think it’s around the 2D arrays I use, but very difficult to find the root cause.

Thanks,
Malcolm

Have you tried opening a Remote Console window while it is running? You should be able to see more about the error.

I use BrowserStack for testing and digging deeper into the console there, the error seems to be coming from code that is populating drop down menus in ComboBox at load. The code looks like this for each combobox and the error is on the addItem part “Uncaught TypeError: RoomID.addItem is not a function”

For i = 0 to 15
    RoomID.addItem(array(i))
Next

This works fine on desktop browser with no errors as well as VoltBuilder to iOS. its only giving an error on Android.

That means RoomID not an array. You might want to trace that backwards.

RoomID is not an array, it is a Bootstrap Select control.
I’m adding items to the list in runtime, so I don’t know why it’s giving an error only on Android.

Yes, BootStrap Select does have an addItem function. In this case, it looks like RoomID is not acting as a Select control. Looking into that would be next.

Okay, but I’m not sure how I can look into that further. The Select control is on the form with that name. As far as I know there is not other declarations I need to do for a select control, is that correct. Since it works fine in Chrome i’m at a loss where to go next.

I would connect using the Remote Console and see what is in RoomID. You can then add some console.log() statements to trace how its value changes from startup.

Okay, so to try to keep things as simple I have removed everything in the app down to a single form, with at single select box control, and the code below. This simple test app runs without error in Chrome, but still generates “Uncaught TypeError: RoomSelect.addItems is not a function in code.js” on Browserstack.

Attached is the APK generated by Voltbuilder. There must be some issue with the voltbuilder generation to cause the error.

Dim i
Sub Main()
  For i = 1 To 50
    RoomSelect.addItem("hello")
  Next  
End Sub

Sycorp Calc Pro.debug.v2.5.2.zip (3.6 MB)

Were you able to connect using the Remote Console?

What is in RoomSelect?

I downloaded your project, installed it on a device and used the RemoteConsole. I examined the value of RoomSelect and I think I have the answer for you.

RoomSelect does have a reasonable value after the program starts. The problem is that Sub Main is called as soon as the program starts, while all the controls are still being instantiated. RoomSelect has not been initialized when you call addItem on it.

The solution is to add the items a bit later in the startup process, by either putting it somewhere else in your code or by using a SetTimeout statement.

The reason you have not seen this before is that timing can work a bit differently in each way you run the app.

I do not not have a physical android device so I have to rely on Browser stack. I can’t connect with Remote Console to it, but they do have pretty good console. RoomSelect is just a dummy select control for test purposes, I tried to make as simple a program as possible to test.

That makes some sense if it’s not initialized yet. I will play around with setTimeout and see. is there any function or setting that get be used or read to indicate that all controls are initialized?
Thanks

If you give SetTimeout 500 msecs, it should work OK.

That did the trick! Thank you for your help