Android Question String Array After 4999 Items ArrayIndexOutOfBoundsException

ronovar

Active Member
Licensed User
Longtime User
I have string array in my apk that works great up to 4999 items, and when i get 5000 item it get's this error:

B4X:
java.lang.ArrayIndexOutOfBoundsException: length=5000; index=-1

So up to 4999 items it works great without error message, but when 5000 item is comming to be read into array i get above message. I have 6000 items to be filled into array so need solution how to put these items into string array (plan is 10 000 items in feauture).

Here is the code that gives me this error:

B4X:
'REDEFINE - Arrays
Dim MovieInfo(Menu.VideoClubList.Size, 13) As String

So as you can see i im reinitializing existing array that have 13 items and it's size is defined in Menu.VideoClubList.Size that have size of 6000 items. You can try in your program to initialize array and try to fill 6000 items into that array and you will get error...i think that String could not handle more that 4999 items if i im right so need another solutio how to fix this.

So try this in attached program.
 

Attachments

  • test.zip
    6.7 KB · Views: 285

Erel

B4X founder
Staff member
Licensed User
Longtime User
You are not redefining the array. You are creating a two dimensions array with the second rank set to 0.

i think that String could not handle more that 4999 items if i im right so need another solutio how to fix this.
You are wrong. There is no limit except of the available memory. Example of an array with million items:
B4X:
Dim MillionMovies (1000000) As String
For i = 0 To MillionMovies.Length - 1
   MillionMovies(i) = "a"
Next
Log(MillionMovies.Length)

The correct solution however is to use a List instead of an array. It is explained in the video tutorials.
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
Ok..thanks..i got now to use list..could you please write me code how to define 2d list? I could not find it in your tutorial...so how to define 2d list like this array:
B4X:
Dim MovieInfo(Menu.VideoClubList.Size, 13) As String

And how then to put word "a" into that 2d list?

Thanks.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…