Note that there are some explanatory texts on larger screens.

plurals
  1. POMain method wont compile cannot find symbol to create an object
    primarykey
    data
    text
    <p>im new to java so I imagine this is a very simple question but I cannot find my answer</p> <p>Im creating a very simple game but when i come to compile my main I get </p> <pre><code> 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 </code></pre> <p>So when i go to create my object in the main it cannot find the symbol and create the object</p> <p>My battle ship class :</p> <pre><code>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; } } </code></pre> <p>Main method :</p> <pre><code>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); } } </code></pre> <p>If anyone could let me know why i cant create an object?</p> <p>I compiled the battleship class before the main These are both in the same package do I still have to import? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload