我刚开始学习java,我正在开发一个程序。我在这里遇到错误:
locationsOfCells = simpleDotCom.getLocationCells();
但我不确定错误是什么。日食说
无法
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]);
}
}
}