JDelage
JDelage

Reputation: 13672

Java cannot find symbol enum

I'm modeling a chess game on Java, and I'm having some problem. Here's what the code looks like (the relevant parts):

Enum class Couleur.java:

public enum Couleur {BLANC, NOIR}

Piece.java:

public abstract class Piece {
(...)
  public Piece(Couleur couleurParam){
    this.couleurPiece = couleurParam;
  }
(...)
}

And finally Tour.java:

public class Tour extends Piece {
(...)
  public Tour(Couleur couleurParam){
    super(couleurParam);
  }
(...)
}

All the .java files are in the same folder. Yet at compile I get a "cannot find symbol symbol : variable NOIR location: class Plateau"

(Plateau is the class that instantiates Tour.)

Can anyone help me figure out what's wrong here?

Many thanks,

JDelage

Upvotes: 2

Views: 7969

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500595

It doesn't help that you've not shown the line in Plateau that fails to compile. If you're getting compilation errors, please post the bit of code which doesn't compile. My guess is you're doing this:

new Tour(NOIR)

instead of

new Tour(Couleur.NOIR)

The only times you can refer to enum values without qualifying them like this are:

  • Within the enum itself
  • Using a static import
  • In a switch statement

Upvotes: 6

Related Questions