我刚开始学习java,我正在开发一个程序。我在这里得到一个错误:无法更正我的java程序
locationsOfCells = simpleDotCom.getLocationCells();
但我不知道错误是什么。 ECLIPSE说
不能使静态参考非静态方法
getLocationCells()
从类型simpleDotCom
有人可以帮助我?我究竟做错了什么?
public class simpleDotCom {
int[] locationsCells;
void setLocationCells(int[] loc){
//Setting the array
locationsCells = new int[3];
locationsCells[0]= 3;
locationsCells[1]= 4;
locationsCells[2]= 5;
}
public int[] getLocationCells(){
return locationsCells;
}
}
public class simpleDotComGame {
public static void main(String[] args) {
printBoard();
}
private static void printBoard(){
simpleDotCom theBoard = new simpleDotCom();
int[] locationsOfCells;
locationsOfCells = new int[3];
locationsOfCells = theBoard.getLocationCells();
for(int i = 0; i<3; i++){
System.out.println(locationsOfCells[i]);
}
}
}
简单的解决方法是,定义方法'static'或创建主simpleDotCom'的'一个对象,然后调用'obj.getLocationCells()” –