Martin Domian Member Licensed User Longtime User Jul 23, 2025 #1 I wanted to create an array of images because they'll be needed in a later loading routine and will be loaded using an index corresponding to the number in the array. But it keeps crashing when INIT the bitmap. BM(i).Initialize(File.DirAssets, Filename) If I use Dim BM1 as ... BM2 as ... it works, but that's nonsense. Does anyone know what's wrong here? Code: Copy Dim BM(1 To 11) As Bitmap Dim Filename As String For i = 1 To 11 Filename = "CL" & NumberFormat(i, 2, 0) & ".png" If File.Exists(File.DirAssets, Filename) Then BM(i).Initialize(File.DirAssets, Filename) Else Log ("Mist") End If Next Error: java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
I wanted to create an array of images because they'll be needed in a later loading routine and will be loaded using an index corresponding to the number in the array. But it keeps crashing when INIT the bitmap. BM(i).Initialize(File.DirAssets, Filename) If I use Dim BM1 as ... BM2 as ... it works, but that's nonsense. Does anyone know what's wrong here? Code: Copy Dim BM(1 To 11) As Bitmap Dim Filename As String For i = 1 To 11 Filename = "CL" & NumberFormat(i, 2, 0) & ".png" If File.Exists(File.DirAssets, Filename) Then BM(i).Initialize(File.DirAssets, Filename) Else Log ("Mist") End If Next Error: java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
stevel05 Expert Licensed User Longtime User Jul 23, 2025 #2 The syntax of your dim statement is incorrect. It should be B4X: Copy Dim BM(10) As Bitmap . The array index is zero based, so your loop should be B4X: Copy For I = 0 to BM.Length -1 Upvote 1
The syntax of your dim statement is incorrect. It should be B4X: Copy Dim BM(10) As Bitmap . The array index is zero based, so your loop should be B4X: Copy For I = 0 to BM.Length -1
Sagenut Expert Licensed User Longtime User Jul 23, 2025 #3 @stevel05 But it should be B4X: Copy Dim BM(11) As Bitmap If not it will count 0 to 9. Upvote 0
stevel05 Expert Licensed User Longtime User Jul 23, 2025 #4 Sagenut said: count Click to expand... Just an example, dimension it as needed. Last edited: Jul 23, 2025 Upvote 0
Martin Domian Member Licensed User Longtime User Jul 23, 2025 #5 Oh ... no! Dim BM(11) As Bitmap That's it... Thanks Upvote 0
TILogistic Expert Licensed User Longtime User Jul 24, 2025 #6 It is better to use List or Map. Upvote 0