Android Question Array error

tdocs2

Well-Known Member
Licensed User
Longtime User
GREETINGS!

THANK YOU FOR ANSWERING THIS REALLY NEWBIE QUESTION!

I feel I have walked into the twilight zone...

Code: Copy
Dim a1() As String
    For i = 0 To 5
        a1(i)="T"&i
    Next

ERROR:
java.lang.ArrayIndexOutOfBoundsException: length=0; index=0

"T"&i are used for illustration purposes and represent variables coming from a data base.

This is not a case of loading constants into an array like:

Code: Copy
Dim a1() As String = Array As String("Ian", "Mark", ...)

Any help will be welcomed.
 
You are creating an empty array.

You should set the size when you declare the array (assuming that you are not assigning a different array like in the second code snippet):
Code: Copy
Dim a1(6) As String
For i = 0 To 5  '5 could be any number dependent on the data base input
...

Thank you, Erel.

I wanted a dynamic array. I do not know how many values are coming in from the data base. The number 5 could be n...

I know this works:

Code: Copy
    Dim list1 As List
    list1.Initialize
    For i = 0 To 5
        list1.Add("T"&i)
    Next

Is the list the correct control to be used for dynamic arrays?

Thanks again.

Sandy
 
Last edited:
Upvote 0

Similar Threads

Back
Top