The array has to be initialized before it can store elements. So before you do
Code:
some_array[0] = "something";
you have to call
Code:
some_array = new String[12]
Change the number 12 in the brackets to the number of elements you want the array to be able to store. If it's 12, you can store 12 elements, and the last index is 11.
Only declares the variable "some_array" as a StringArray which has the value "null".
Adding the "= new..." initiates it and actually creates a new StringArray object to which you can then assign Strings. Unfortunately you always have to give the max length of the array when initializing it :-/
Alternately your could use and ArrayList of Strings, which will give some more flexibility regarding length etc.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.