【发布时间】:2019-05-10 00:14:45
【问题描述】:
对于以下代码,我不断收到此数组越界错误。
brock.txt = 反射程序,例程,箭,蛇游戏,
public static void main(String[] args) {
String filename = "brock.txt";
String line;
String [] cities = {};
int x = 0;
try {
BufferedReader eshread = new BufferedReader( new FileReader (filename));
line = "";
while ((line = eshread.readLine()) != null ) {
String[] store = line.split(",");
System.out.println(store[0]);
System.out.println(store[1]);
System.out.println(store[2]);
cities[x] = store[2]; //< keep getting an error here
x++;
}//end while loop
eshread.close();
}//end try
catch(IOException iox) {
System.out.println("failiure");
}//end catch
【问题讨论】:
-
String [] cities = {}这就是原因