即時通訊新到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);
}
}
如果有人可以讓我知道爲什麼我不能創建一個對象?
我在主編前編制了戰列艦級別 這兩個都是在同一個包裏還要導入嗎?
你是如何編譯這個? –
你有導入戰艦班嗎? –
在BattleShipGame類中導入BattleShip類。 –