我有一个数组错误,说它出界了,我不知道什么是错的。这里是我的代码:字符串数组错误
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];
}
和第二类(这里我得到第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])
}
}
}
你的帮助深表感谢!
确定'nameArray [计数器]'是在循环'counter'的每个值有效的价值? – Aiias 2013-03-24 08:17:33