首页 文章

错误:找不到符号ArrayList

提问于
浏览
7

我正在尝试创建某种列表来存储数组'table'中的值 . (我在这里使用arraylist,但是我应该使用列表吗?)但是,每次我尝试编译时,都会抛出以下错误:

找不到符号符号:class ArrayList location:class players.TablePlayer

代码如下 .

public class TablePlayer extends Player {

    int[][] table;
    ArrayList goodMoves;


    public TablePlayer(String name) {
        super(name);
    }

    @Override
    public int move() {
        int oppLast = opponentLastMove();
        int myLast = myLastMove();
        if (!isLegalMove(oppLast)) {
            return 0; // temporary
        }
        if (wonLast()) {
            table[oppLast][myLast] = 1;
            table[myLast][oppLast] = -1;
        }
        if ((wonLast() == false) && (oppLast != myLast)) {
            table[oppLast][myLast] = -1;
            table[myLast][oppLast] = 1;
        }
        for (int i = 0; i < table.length; i++) {
            for (int j = 0; j < table.length; j++) {
                if (table[i][j] == 1) {
                    goodMoves.add(table[i][j]);
                }
            }
        }

        return oppLast; // temporary
    }

    @Override
    public void start() {
        int[][] table = new int[7][7];
        ArrayList<int> goodMoves = new ArrayList<int>();
    }
}

任何帮助都会很棒,谢谢!

2 回答

  • 0

    你在文件的顶部有一个import语句吗?

    import java.util.ArrayList;
    
  • 17

    在使用类之前,需要将其导入到类文件定义中 .

    将其添加到您的文件之上:

    import java.util.ArrayList;

    有关导入的更多信息,请查阅here

    建议学习如何使用IDE,如Eclipse,Netbeans . 当我们在集成环境之外使用Java(在本例中)编程时,它将帮助您解决这些常见错误 .

相关问题