...
Caused by: java.lang.ExceptionInInitializerError
...
Caused by: java.lang.ClassCastException:
class com.evopulse.ds2150.TechTrees$BuildingTechTree
not an enum
at java.util.EnumSet.noneOf(Unknown Source)
at java.util.EnumSet.of(Unknown Source)
at com.evopulse.ds2150.TechTrees$BuildingTechTree.<clinit>(TechTrees.java:38)
Ecco un frammento della mia enumerazione
public enum BuildingTechTree {
//Name SoftName Requirements
NONE ("NULL", null),
-> Questa riga successiva è dove si blocca
BARRACKS ("Barracks", EnumSet.of(NONE),
WALLS_SANDBAGS ("Sandbag wall", EnumSet.of(NONE),
POWERPLANT ("Power plant", EnumSet.of(BARRACKS)),
GUARDTOWER ("Guard Tower", EnumSet.of(BARRACKS));
Sostituzione EnumSet.of (NESSUNO) e EnumSet.of (BARRACKS) con null, immobili in lavoro di itialization, ma rompe il mio codice, a causa della struttura dei dati mancante ... ovviamente, ma l'ho fatto per testare il resto del mio codice non era in qualche modo la causa.
Rimozione di EnumSet.of (NONE) e sostituzione con solo NONE, e lo stesso per BARRACKS, e modifica di tutte le variabili correlate, costruttore e metodi, che non ha funzionato neanche ... (e anche non poteva usare il contains.all, poiché non è non era "applicabile al mio cambiato variabile" ...)
ho esteso questo esempio, utilizzando la seconda realizzazione: https://gamedev.stackexchange.com/a/25652/48573
ho provato anche sui miei passi copiando il esempio verbatim. aggiunto
private static Set<BuildingTechTree> techsKnown;
techsKnown = (BuildingTechTree.BIODOME);
test = TechTrees.researchTech(techsKnown);
in un'altra classe da richiamare per l'inizializzazione del test. e ho dovuto cambiare
public boolean researchTech(BuildingTechTree tech) {
alla statica
Ciò ha provocato lo stesso errore "in non un enum". Non ho alcun rappresentante, per commentare la sua risposta a sottolineare l'errore di inizializzazione ...
Aggiunto informazioni per entrambe le risposte attuali, come entrambe le soluzioni provocano lo stesso nuovo errore:
public class TechTrees {
private static Set<BuildingTechTree> techsKnown;
public TechTrees() {
techsKnown = EnumSet.of(BuildingTechTree.NONE); //Using this
techsKnown = EnumSet.noneOf(BuildingTechTree.class); //Or this
}
public static boolean researchTech(BuildingTechTree tech) {
if (techsKnown.containsAll(tech.requirements)) { //Causes null pointer
return true; //exception @ techsKnown
}
return false;
}
Vedere la risposta modificata per il tuo secondo problema. –