找不到标志

时间:2014-03-13 21:05:08

标签: java compiler-construction scope symbols

在查看我的代码之后,我无法理解为什么javac会发出“找不到符号”。我已经查看了Stackoverflow中的一些问题我明白这与范围有关,但我作为一个血腥的初学者仍然无法解决这个问题。

请帮助。谢谢

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;
    }


}

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

GameManager的Stacktrace:

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。

2 个答案:

答案 0 :(得分: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

您是否拥有所需的所有*.java个文件? 。似乎缺少课程。请记住,还需要GameManager

答案 1 :(得分:0)

这些类是泛型类,它们必须保留在“final1.algorithm”包中,Terminal类应该在final1包中。 你甚至不允许更改它们中的任何内容(包名称),因为当你将程序上传到网站时,它会自动添加这些类以防止你对它们进行任何更改,当然因为它们有更多的隐藏测试在那里实施。

您可以将自己编写的类放在final1包中或任何其他所需的子包中,但不要忘记正确导入所有内容。