配列エラーが発生しました。範囲外であり、何が問題なのかわかりません。これが私のコードです:
import java.util.*;
public class gameVar {
public static int size;
public static int counter;
public static Scanner input = new Scanner(System.in);
public static String currentIn;
public static String nameArray[] = new String[size];
}
および2番目のクラス(6行目でエラーが発生している場所):
public class mainThread extends gameVar {
public static void main(String[] args){
System.out.println("Please type the desired amount of players: ");
size = input.nextInt();
for(int counter = 0; counter < size; counter++){
System.out.println("Please enter the name of player " + nameArray[counter])
}
}
}
あなたの助けは大歓迎です!