saunwin Active Member Licensed User Longtime User Sep 24, 2015 #1 Hi Guys and Gurus Dim b() as byte b(1) = 129 crashes program with java.lang.ArrayIndexOutOfBoundsException: 2 Why ? Thanks in advance.
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 Sep 24, 2015 #2 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
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).
saunwin Active Member Licensed User Longtime User Sep 24, 2015 #3 Hi Daestrum, Thanks for the reply. It does work when dimensioning an array of known size (a number inside the brackets). Cheers Upvote 0
Hi Daestrum, Thanks for the reply. It does work when dimensioning an array of known size (a number inside the brackets). Cheers
Erel B4X founder Staff member Licensed User Longtime User Sep 24, 2015 #4 Dim b() As Byte creates an empty array. B4X: Dim b(1) As Byte b(0) = 129 Or better: B4X: Dim b() As Byte = Array As Byte(129) Upvote 0
Dim b() As Byte creates an empty array. B4X: Dim b(1) As Byte b(0) = 129 Or better: B4X: Dim b() As Byte = Array As Byte(129)