我是 java 新手,所以我想这是一个非常简单的问题,但我找不到答案
我正在创建一个非常简单的游戏,但是当我开始编译我的主要游戏时,我得到了
BattleShipGame.java:19: error: cannot find symbol
BattleShip ship = new BattleShip();
^
symbol: class BattleShip
location: class BattleShipGame
BattleShipGame.java:19: error: cannot find symbol
BattleShip ship = new BattleShip();
^
symbol: class BattleShip
location: class BattleShipGame
2 errors
所以当我去主要创建我的对象时,它找不到符号并创建对象
我的战舰等级:
public class BattleShip {
//delcare an int arry to hold the location of the cells
private int[] location;
//setter for location
public void setLocation(int[] shipLocation){
location = shipLocation;
}
public String checkGuess(String[] g){
//return the message
return message;
}
}
主要方法:
public class BattleShipGame {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//create a battle ship object
BattleShip ship = new BattleShip();
//hard code location of ship
int[] ShipLocation = {4,5,6};
//set the location of the object
ship.setLocation(ShipLocation);
//take the users guess from command line
String[] guess = {args[0], args[1], args[2]};
//take message returned from method
String message = ship.checkGuess(guess);
// print out the message
System.out.println(message);
}
}
如果有人可以让我知道为什么我不能创建一个对象?
我在main之前编译了战舰类这些都在同一个包中我还需要导入吗?