Can't use enum in Java (Error:Can't find symbol)

Can't use enum in Java (Error:Can't find symbol)

所以我有一个 class 文件,其中只有我的枚举,看起来像这样

public class FactionNames {
    public enum Faction {AMITY, ABNEGATION, DAUNTLESS, ERUDITE, CANDOR};
}

我有一个 class 在构造函数中使用这些枚举,如下所示

public Dauntless(String f, String l, int a,  int ag, int end, Faction d) {
        super(f, l, a, d);
        if (ag >= 0 && ag <= 10) {
            this.agility = ag;
        } else {
            this.agility = 0;
        }
        if (end >= 0 && end <= 10) {
            this.endurance = end;
        } else {
            this.endurance = 0;
        }
    }

因此,为了确保此 class 中的所有内容正常工作,我想在驱动程序中创建一些 Dauntless 对象,但我不断收到这些错误

D:\Documents\Google Drive\Homework31
Test.java:3: error: cannot find symbol
        Faction test;
        ^
  symbol:   class Faction
  location: class Test
Test.java:4: error: cannot find symbol
        test = Faction.DAUNTLESS;
               ^
  symbol:   variable Faction
  location: class Test
2 errors 

我正在使用看起来像这样的驱动程序。我的语法有什么问题吗?我不知道为什么我会收到这个错误。

public class Test {
    public static void main(String[] args) {
        Faction test; 
        test = Faction.DAUNTLESS;
        Dauntless joe = new Dauntless("Joseph", "Hooper", 20, 5, 3, test);
        Dauntless vik = new Dauntless("Victoria", "Ward", 19, 6, 2, test);
        Dauntless winner;
        winner = joe.battle(vik);
        System.out.println(winner);

    }
}

enum 类型 Faction 嵌套在顶层 class FactionNames

public class FactionNames {
    public enum Faction {AMITY, ABNEGATION, DAUNTLESS, ERUDITE, CANDOR};
}

如果您想使用它的简单名称,则需要导入它

import com.example.FactionNames.Faction;

或者,您可以使用其限定名称

FactionNames.Faction test = FactionNames.Faction.DAUNTLESS;