Android Question Dim Array

Giusy

Active Member
Licensed User
Hi
I just have to size an array
B4X:
Sub Globals
   Dim NOME(12) As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
   
    NOME(1)="DSDSD"
    NOME(2)="DSDSD"
    NOME(3)="DSDSD"
    NOME(4)="DSDSD"
    NOME(5)="DSDSD"
    NOME(6)="DSDSD"
    NOME(7)="DSDSD"
    NOME(8)="DSDSD"
    NOME(9)="DSDSD"
    NOME(10)="DSDSD"
    NOME(11)="DSDSD"
    NOME(12)="DSDSD"
End Sub
and I have this error:
Error occurred on line 42 (Main)
java.lang.ArrayIndexOutOfBoundsException: length=12; index=12

Why?
 

Star-Dust

Expert
Licensed User
Longtime User
B4X:
Sub Globals
   Dim NOME(12) As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
    NOME(0)="DSDSD"
    NOME(1)="DSDSD"
    NOME(2)="DSDSD"
    NOME(3)="DSDSD"
    NOME(4)="DSDSD"
    NOME(5)="DSDSD"
    NOME(6)="DSDSD"
    NOME(7)="DSDSD"
    NOME(8)="DSDSD"
    NOME(9)="DSDSD"
    NOME(10)="DSDSD"
    NOME(11)="DSDSD"
End Sub
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
True! I can not believe it, maximum 11?

It's a Java thing. First one is ZERO, not 1.

It's like: In the year 0 the first century began, so 1869 was in the 19th century and we now live in the 21st though it's 2018

Another one: When you measure a wall for wallpapers your meter starts at 0 cm (or inches). The first cm starts at 0. I've never seen one starting at 1
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…