Before my onCreate()
method I can easily declare and initialise data types like int
with the code
int number = 2;
however if I want to do this with an array, using code such as
float[] array = new float[2];
array[0] = 1;
the second line gives me an error. Why is this? Is there a way of initialising this array before the onCreate()
method like I can do with other data types?
An Android Activity is just a normal class. There, regular statements can only be executed in:
methods
instance contructors (that would be bad practise)
"class constructors" / static blocks:
last possebility to set values to your array is on defining it:
I hope this can help you