B4J Question Arrays

saunwin

Active Member
Licensed User
Longtime User
Hi Guys and Gurus

Dim b() as byte
b(1) = 129

crashes program with java.lang.ArrayIndexOutOfBoundsException: 2
Why ?

Thanks in advance.
 

Daestrum

Expert
Licensed User
Longtime User
Arrays start at 0, so b(1) is actually the second item.
Try b(0) in your example above and dimension the array 'Dim b(1) as byte'.
If you want 2 items use Dim b(2) as byte, then you can use b(0) and b(1).
 
Upvote 0

saunwin

Active Member
Licensed User
Longtime User
Hi Daestrum,

Thanks for the reply.
It does work when dimensioning an array of known size (a number inside the brackets).

Cheers
 
Upvote 0
Top