【发布时间】:2015-11-21 19:48:38
【问题描述】:
我正在使用 Eclipse,但出现此错误:
席位无法解析为变量
这是我的程序:
import java.util.*;
class Project {
public static void printRow(char[] row) {
for (char i : row) {
System.out.print(i);
System.out.print("\t");
}
System.out.println();
}
public static void method1 (char[][]seats){
seats = new char [15][4];
int i,j;
char k = 'O';
for(i=0;i<15;i++) {
for(j=0;j<4;j++) {
seats[i][j]=k;
}
}
for(char[] row : seats) {
printRow(row);
}
这是主要的:
public static void main (String[]arg) {
method1(seats);
}
我省略了不相关的代码,Eclipse 标记method1(seats) 有错误,但我不知道如何修复它。
编辑:我为seats 使用了一个参数,因为我需要在其他方法中使用。
【问题讨论】:
-
好吧,例如,在你的 main 中定义一个
seats变量。 -
在
main方法中seats没有定义。它应该是数据成员吗? -
是错字还是您没有在 main 中定义“座位”?
-
为什么
seats是method1的参数?它会立即被覆盖。
标签: java arrays methods compiler-errors