[英]Out of bounds exception error with String[][]
When trying to print out my 2 dimensional String array, I get an error message: 当尝试打印我的二维String数组时,出现错误消息:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at MainClass.main(MainClass.java:51)
This is my array: 这是我的数组:
String[][] list = {
{"1",null},
{"2",null},
{"3",null},
{"4",null},
{"5",null},
{"6",null},
{"7",null},
{"8",null},
{"9",null},
{"10",null},
{"11",null},
{"12",null},
{"13",null},
{"14",null},
{"15",null}
};
And this is how I am printing it out: 这就是我打印出来的方式:
for( int row=0; row<list.length; row++) {
for( int col=0; col<list.length; col++) {
System.out.print(list[row][col] + "\t"); //this is MainClass:java:51 where the error is happenin
}
System.out.println();
}
I am trying to print it out in a nice grid shape. 我正在尝试以漂亮的网格形状打印出来。 The way I am doing it now DOES work for and Integr array so that's what has got me kind of confused. 我现在的工作方式适用于Integr数组,因此这让我感到困惑。
col<list.length
应该是col<list[row].length
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.