Java无法找到符号枚举 [英] Java cannot find symbol enum

查看:172
本文介绍了Java无法找到符号枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java模拟国际象棋游戏,我遇到了一些问题。这是代码的样子(相关部分):

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

枚举类Couleur.java:

Enum class Couleur.java:

public enum Couleur {BLANC, NOIR}

Piece.java:

Piece.java:

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

最后是Tour.java:

And finally Tour.java:


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

所有.java文件都在同一个夹。然而在编译时我得到一个找不到符号
符号:变量NOIR
位置:类高原

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是实例化Tour的类。)

(Plateau is the class that instantiates Tour.)

任何人都可以帮我弄清楚这里有什么问题吗?

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

非常感谢,

JDelage

推荐答案

你没有在Plateau中显示无法编译的行没有帮助。如果您遇到编译错误,请发布无法编译的代码。我的猜测是你这样做:

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)

而不是

new Tour(Couleur.NOIR)

您可以在没有限定条件的情况下引用枚举值的唯一时间是:

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


  • 在enum内部

  • 使用静态导入

  • 在交换机中声明

这篇关于Java无法找到符号枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆