1

After looking through my code up and down I can't understand why javac puts out "Cannot find symbol". I aleready looked through some Questions in Stackoverflow I understand that this has something to do with scope, but still I, as a bloody beginner, can't fix this problem.

Please Help. Thank you

package final1.classes;
import final1.classes.GameManager;

public final class ConnectFour {

    private ConnectFour() {

    }

    private static int playerCount = 0;


/**
 * The main method where the number of players is extracted from the
 * arguments array
 * 
 * @param args
 *            String: Here used as the number of players
 */
    public static void main(String[] args) {

        if (args.length == 0) {

            System.out.println("Please insert a number of players as argument");
            System.exit(0);

        }
        try {
            setPlayerCount(Integer.parseInt(args[0]));

        } catch (IllegalArgumentException ilae) {

            System.out.println("Wrong input! The right input is a digit between 0 and 2");
            System.exit(0);
        }

        if (getPlayerCount() < 0 || getPlayerCount() > 2) {

            System.out.println("Wrong number of players! You have to put in a digit between 0 and 2");

            System.exit(0);

        } else {    

            final1.classes.GameManager game = new final1.classes.GameManager(getPlayerCount());
            game.update();
        }

    }
/**
 * Returns the playerCount
 * @return the playerCount
 */
    public static int getPlayerCount() {
        return playerCount;
    }

/**
 * Sets playerCount to the parameter playerCount
 * @param playerCount the playerCount to set
 */
    public static void setPlayerCount(int playerCount) {
        ConnectFour.playerCount = playerCount;
    }


}

The Stacktrace:

C:\Users\Dennis\Dropbox\workspaceNero\Abschlussaufgabe1\src\final1\classes>javac
 ConnectFour.java
ConnectFour.java:2: error: cannot find symbol
import final1.classes.GameManager;
                     ^
  symbol:   class GameManager
  location: package final1.classes
ConnectFour.java:53: error: cannot find symbol
            final1.classes.GameManager game = new final1.classes.GameManager(get
PlayerCount());
                          ^
  symbol:   class GameManager
  location: package final1.classes
ConnectFour.java:53: error: cannot find symbol
            final1.classes.GameManager game = new final1.classes.GameManager(get
PlayerCount());
                                                                ^
  symbol:   class GameManager
  location: package final1.classes
3 errors

The Stacktrace of GameManager:

C:\Users\Dennis\Dropbox\workspaceNero\Abschlussaufgabe1\src\final1\classes>javac
 GameManager.java
GameManager.java:5: error: package final1.algorithm does not exist
import final1.algorithm.AlphaBetaAlgorithm;
                       ^
GameManager.java:6: error: package final1.algorithm does not exist
import final1.algorithm.Game;
                       ^
GameManager.java:7: error: package final1.algorithm does not exist
import final1.algorithm.GameState;
                       ^
GameManager.java:8: error: package final1.algorithm does not exist
import final1.algorithm.Move;
                       ^
GameManager.java:9: error: package final1.algorithm does not exist
import final1.algorithm.Terminal;
                       ^
GameManager.java:17: error: cannot find symbol
public class GameManager implements Game<Move> {
                                    ^
  symbol: class Game
GameManager.java:17: error: cannot find symbol
public class GameManager implements Game<Move> {
                                         ^
  symbol: class Move
GameManager.java:21: error: cannot find symbol
    private static GameState gameState;
                   ^
  symbol:   class GameState
  location: class GameManager
GameManager.java:39: error: cannot find symbol
    private GameField gf;
            ^
  symbol:   class GameField
  location: class GameManager
GameManager.java:155: error: cannot find symbol
    public List<Move> getValidMoves() {
                ^
  symbol:   class Move
  location: class GameManager
GameManager.java:177: error: cannot find symbol
    public void perform(Move move) {
                        ^
  symbol:   class Move
  location: class GameManager
GameManager.java:210: error: cannot find symbol
    public Move nextTurn() {
           ^
  symbol:   class Move
  location: class GameManager
GameManager.java:221: error: cannot find symbol
    public GameState getState() {
           ^
  symbol:   class GameState
  location: class GameManager
GameManager.java:230: error: cannot find symbol
    public static GameState getGameState() {
                  ^
  symbol:   class GameState
  location: class GameManager
GameManager.java:240: error: cannot find symbol
    public static void setGameState(GameState gameState) {
                                    ^
  symbol:   class GameState
  location: class GameManager
GameManager.java:50: error: cannot find symbol
        this.gameState = GameState.PLAYING;
                         ^
  symbol:   variable GameState
  location: class GameManager
GameManager.java:51: error: cannot find symbol
        gf = new GameField(6, 7);
                 ^
  symbol:   class GameField
  location: class GameManager
GameManager.java:62: error: cannot find symbol
        while (gameState == GameState.PLAYING) {
                            ^
  symbol:   variable GameState
  location: class GameManager
GameManager.java:65: error: cannot find symbol
            Terminal.prompt("Player " + String.valueOf(player) + ":");
            ^
  symbol:   variable Terminal
  location: class GameManager
GameManager.java:75: error: cannot find symbol
                    int column = Integer.parseInt(Terminal.readln());
                                                  ^
  symbol:   variable Terminal
  location: class GameManager
GameManager.java:78: error: cannot find symbol
                        Terminal.println("Please insert a number between 0 and 6
");
                        ^
  symbol:   variable Terminal
  location: class GameManager
GameManager.java:81: error: cannot find symbol
                        this.perform(new ConnectFourMove(column, player));
                                         ^
  symbol:   class ConnectFourMove
  location: class GameManager
GameManager.java:86: error: cannot find symbol
                            Terminal.println("Column" + column
                            ^
  symbol:   variable Terminal
  location: class GameManager
GameManager.java:94: error: cannot find symbol
                    Terminal.println("Please insert a number between 0 and 6");
                    ^
  symbol:   variable Terminal
  location: class GameManager
GameManager.java:99: error: cannot find symbol
                AlphaBetaAlgorithm<Game<Move>, Move> alpha = new AlphaBetaAlgori
thm<Game<Move>, Move>(
                ^
  symbol:   class AlphaBetaAlgorithm
  location: class GameManager
GameManager.java:99: error: cannot find symbol
                AlphaBetaAlgorithm<Game<Move>, Move> alpha = new AlphaBetaAlgori
thm<Game<Move>, Move>(
                                   ^
  symbol:   class Game
  location: class GameManager
GameManager.java:99: error: cannot find symbol
                AlphaBetaAlgorithm<Game<Move>, Move> alpha = new AlphaBetaAlgori
thm<Game<Move>, Move>(
                                        ^
  symbol:   class Move
  location: class GameManager
GameManager.java:99: error: cannot find symbol
                AlphaBetaAlgorithm<Game<Move>, Move> alpha = new AlphaBetaAlgori
thm<Game<Move>, Move>(
                                               ^
  symbol:   class Move
  location: class GameManager
GameManager.java:99: error: cannot find symbol
                AlphaBetaAlgorithm<Game<Move>, Move> alpha = new AlphaBetaAlgori
thm<Game<Move>, Move>(
                                                                 ^
  symbol:   class AlphaBetaAlgorithm
  location: class GameManager
GameManager.java:99: error: cannot find symbol
                AlphaBetaAlgorithm<Game<Move>, Move> alpha = new AlphaBetaAlgori
thm<Game<Move>, Move>(

    ^
  symbol:   class Game
  location: class GameManager
GameManager.java:99: error: cannot find symbol
                AlphaBetaAlgorithm<Game<Move>, Move> alpha = new AlphaBetaAlgori
thm<Game<Move>, Move>(

         ^
  symbol:   class Move
  location: class GameManager
GameManager.java:99: error: cannot find symbol
                AlphaBetaAlgorithm<Game<Move>, Move> alpha = new AlphaBetaAlgori
thm<Game<Move>, Move>(

                ^
  symbol:   class Move
  location: class GameManager
GameManager.java:101: error: cannot find symbol
                AlphaBetaAlgorithm<Game<Move>, Move> beta = new AlphaBetaAlgorit
hm<Game<Move>, Move>(
                ^
  symbol:   class AlphaBetaAlgorithm
  location: class GameManager
GameManager.java:101: error: cannot find symbol
                AlphaBetaAlgorithm<Game<Move>, Move> beta = new AlphaBetaAlgorit
hm<Game<Move>, Move>(
                                   ^
  symbol:   class Game
  location: class GameManager
GameManager.java:101: error: cannot find symbol
                AlphaBetaAlgorithm<Game<Move>, Move> beta = new AlphaBetaAlgorit
hm<Game<Move>, Move>(
                                        ^
  symbol:   class Move
  location: class GameManager
GameManager.java:101: error: cannot find symbol
                AlphaBetaAlgorithm<Game<Move>, Move> beta = new AlphaBetaAlgorit
hm<Game<Move>, Move>(
                                               ^
  symbol:   class Move
  location: class GameManager
GameManager.java:101: error: cannot find symbol
                AlphaBetaAlgorithm<Game<Move>, Move> beta = new AlphaBetaAlgorit
hm<Game<Move>, Move>(
                                                                ^
  symbol:   class AlphaBetaAlgorithm
  location: class GameManager
GameManager.java:101: error: cannot find symbol
                AlphaBetaAlgorithm<Game<Move>, Move> beta = new AlphaBetaAlgorit
hm<Game<Move>, Move>(

s.o.

  • Why do you have a constructor, when everything in your class is static? – blueygh2 Mar 13 '14 at 21:09
  • You don't need to import classes that are in the same package. – Luiggi Mendoza Mar 13 '14 at 21:12
  • @Luiggi Mendoza. I would post the stacktrace but I'm a prety new user here so I'M either too stupid to edit this post, or I'm not allowed to.. rpax pretty much replicadet the problem – user3417347 Mar 13 '14 at 21:24
  • @user3417347 anybody that only have this class and doesn't have the definition of your `GameManager` could replicate this problem... And you're allowed to always edit your posts since you're the owner of them. – Luiggi Mendoza Mar 13 '14 at 21:25
  • @Luiggi Mendoza I had some problem with a program on Firefox, which made the edit button not clickable for me, sorry about that. – user3417347 Mar 13 '14 at 21:30
  • So, from your current problem, looks like you haven't compiled `GameManager` class. Please compile that class first using `javac` as well and make sure it is in the expected package. – Luiggi Mendoza Mar 13 '14 at 21:33
  • @LuiggiMendoza Something is going horribly wrong... when I try to compile `GameManager` class the stracktrace shown as above happens – user3417347 Mar 13 '14 at 21:49
  • @user3417347 Well to build GameManager you have to have buildt Game, Move, GameField, GameState and so on. All used classes. – Tomas Mar 13 '14 at 22:43

2 Answers2

0
$ javac ConnectFour.java 
ConnectFour.java:2: error: cannot find symbol
import final1.classes.GameManager;
                     ^
  symbol:   class GameManager
  location: package final1.classes
ConnectFour.java:49: error: cannot find symbol
        final1.classes.GameManager game = new final1.classes.GameManager(getPlayerCount());
                      ^
  symbol:   class GameManager
  location: package final1.classes
ConnectFour.java:49: error: cannot find symbol
        final1.classes.GameManager game = new final1.classes.GameManager(getPlayerCount());
                                                            ^
  symbol:   class GameManager
  location: package final1.classes

Do you have all the *.java files you need? . It seems there are missing classes. Remember that GameManager is also needed.

rpax
  • 4,468
  • 7
  • 33
  • 57
0

These classes are generic classes and they must remain in package "final1.algorithm" and the Terminal class should be in final1 package. You are not allowed to change anything in them not even the (package name) because when you upload your program to the website it will automatically add these classes to prevent you from making any changes in them and of course because they have more hidden tests that are implemented there.

You may put your own written classes in final1 package or in any other sub-packages that you want but don't forget to correctly import everything.