Android Question What is the problem, when it comes to this error.

HaIm

Member
Licensed User
Longtime User
Hi
I have bluetooth application. Program running but sometimes come error box:


Arrow (->) show codeline 566

Sub mnuConnect_Click
Dim PairedDevices As Map
PairedDevices = Serial1.GetPairedDevices
Dim l As List
l.Initialize
For i = 0 To PairedDevices.Size - 1
l.Add(PairedDevices.GetKeyAt(i))
Next
Dim res As Int

res=0 ' first device from list

If res <> DialogResponse.CANCEL Then
-> Serial1.Connect(PairedDevices.Get(l.Get(res))) 'convert the name to mac address
End If

Wait(300)

End Sub
 

HaIm

Member
Licensed User
Longtime User
Text in picture :
Error occurred
An error has occurred in sub:main_mnuconnect_click(java line:566)
java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
Continue?
No | Yes

Who know?
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
Chances are you don't have any paired devices and so whilst you are trying to access item 0, it does not exist and so you get the out of bounds error. To prevent this you could check that the size is 1 or more first.
 
Upvote 0
Top