Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: cannot find symbol ArrayList

Tags:

java

arraylist

I'm trying to create some kind of list to store values from the array 'table'. (I'm using a arraylist here, but should I be using a list instead?) However, every time I try to compile, it throws the following error:

cannot find symbol symbol : class ArrayList location: class players.TablePlayer

The code is below.

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

Any help would be great, thanks!

like image 371
csstudent Avatar asked Apr 03 '13 13:04

csstudent


People also ask

What does error Cannot find symbol mean in Java?

The cannot find symbol error, also found under the names of symbol not found and cannot resolve symbol , is a Java compile-time error which emerges whenever there is an identifier in the source code which the compiler is unable to work out what it refers to.

How do you find the length of an ArrayList?

The size of an ArrayList can be obtained by using the java. util. ArrayList. size() method as it returns the number of elements in the ArrayList i.e. the size.


Video Answer


2 Answers

While doing any java program just

import java.util.*;

Because * will import all the packages from util.

And all the basic package are present in that java.util like Scanner, ArrayList, etc...

So to avoid errors first check you have imported that.

like image 133
Shubham Teke Avatar answered Oct 09 '22 01:10

Shubham Teke


Do you have an import statement in the top of the file?

import java.util.ArrayList;
like image 20
mrks Avatar answered Oct 09 '22 01:10

mrks