From what you've posted, the lines
test1[0] = 1;
test1[1] = 2;
test1[2] = 3;
need to be inside a method or constructor. Looks like you have them outside at the class level. Lets say MyClass
is the name of your class. Add a constructor and put the three statements inside it:
MyClass {
test1[0] = 1;
test1[1] = 2;
test1[2] = 3;
}
Edit: You can only declare variables directly inside the class. A declaration statement can, however, also include initialization (on the same line):
int[] arrayA; // declare an array of integers
int[] arrayB = new int[5]; // declare and create an array of integers
int[] arrayC = {1, 2, 3}; // declare, create and initialize an array of integers
The following, on the other hand, is not a declaration and involves only initialization:
arrayB[0] = 1;
and so it can't go directly under the class. It must be enclosed within a method, constructor or initialization block.
See Also:
Arrays Java tutorial at Oracle