我正在尝试填充ChoiceBox,并且我一直得到一个nullpointer异常 我有这个
ObservableList<Integer> test = FXCollections.observableArrayList(1,2,3);
和这个
@FXML
private ChoiceBox<Integer> Level;
在我的控制器类中,然后在初始化函数
中Level.setItems(test);
Level.setValue(1);
我不确定为什么我会得到nullpointer异常。我在另一个程序中做了完全相同的事情,它工作得很好。
public class EnterStatsController {
//ObservableList<String> RaceBox = FXCollections.observableArrayList();
ObservableList<Integer> statBox = FXCollections.observableArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);
ObservableList<String> ClassBox = FXCollections.observableArrayList("Barbarian", "Bard", "Cleric", "Druid", "Fighter", "Monk", "Paladin", "Ranger", "Rogue", "Sorcerer", "Warlock", "Wizard", "Homebrew");
ObservableList<String> RaceBox = FXCollections.observableArrayList("Aasimar", "Bugbear", "Dragonborn", "Dwarf", "Elf", "Firbolg", "Genasi", "Gnome", "Goblin", "Goliath", "Half-Elf", "Half-Orc", "Halfling", "Hobgoblin", "Human", "Kenku", "Kobold", "Lizardfolk", "Orc", "Tabaxi", "Tiefling", "Tortle", "Triton", "Yuan-Ti Pureblood", "Homebrew");
ObservableList<String> BackgroundBox = FXCollections.observableArrayList("Acolyte", "Charlatan", "Criminal", "Entertainer", "Folk Hero", "Guild Artisan", "Hermit", "Noble", "Outlander", "Sage", "Sailor", "Soldier", "Urchin", "Homebrew");
ObservableList<String> AlignmentBox = FXCollections.observableArrayList("Lawful Evil", "Lawful Good", "Lawful Neutral", "Chaotic Evil", "Chaotic Good", "Chaotic Neutral", "True Neutral");
ObservableList<String> BarbarianClassBox = FXCollections.observableArrayList("Path of the Ancestral Guardian", "Path of the Battlerager", "Path of the Berserker", "Path of the Storm Herald", "Path of the Totem Warrior", "Path of the Totem Warrior", "Path of the Zealot");
ObservableList<String> BardClassBox = FXCollections.observableArrayList("College of Glamour", "College of Lore", "College of Satire", "College of Swords", "College of Valor", "College of Whispers");
ObservableList<String> ClericClassBox = FXCollections.observableArrayList("Arcana Domain", "City Domain", "Death Domain", "Forge Domain", "Grave Domain", "Knowledge Domain", "Life Domain", "Light Domain", "Nature Domain", "Protection Domain", "Tempest Domain", "Trickery Domain", "War Domain");
ObservableList<String> DruidClassBox = FXCollections.observableArrayList("Circle of Dreams", "Circle of the Land", "Circle of the Moon", "Circle of the Shepherd", "Circle of Spores", "Circle of Twilight");
ObservableList<String> FighterClassBox = FXCollections.observableArrayList("Arcane Archer", "Banneret/Purple Dragon Knight", "Battle Master", "Brute", "Cavalier", "Champion", "Eldritch Knight", "Knight", "Samuria", "Sharpshooter");
ObservableList<String> MonkClassBox = FXCollections.observableArrayList("Way of the Drunker Master", "Way of the Four Elements", "Way of the Kensei", "Way of the Long Death", "Way of the Open Hand", "Way of the Shadow", "Way of the Sun Soul", "Way of the Tranquility");
ObservableList<String> PaladinClassBox = FXCollections.observableArrayList("Oath of the Ancients", "Oath of Conquest", "Oath of the Crown", "Oath of Devotion", "Oath of Redemption", "Oath of Treachery", "Oath of Vengence", "Oathbreaker");
ObservableList<String> RangerClassBox = FXCollections.observableArrayList("Beat Master", "Gloom Stalker", "Horizon Walker", "Hunter", "Moster Slayer", "Primeval Guardain");
ObservableList<String> RogueClassBox = FXCollections.observableArrayList("Arcane Trickster", "Assassin", "Inquisitive", "Mastermind", "Scout", "Swashbuckler", "Theif");
ObservableList<String> SorcererClassBox = FXCollections.observableArrayList("Divine Soul", "Draconic Bloodline", "Pheonix Sorcery", "Sea Sorcery", "Shadow Magic", "Stone Sorcery", "Storm Sorcery", "Wild Magic");
ObservableList<String> WarlockClassBox = FXCollections.observableArrayList("The Archfey", "The Clelestial", "THe Fiend", "Ghost in the Machine", "The Great Old One", "The Hexblade", "The Raven Queen", "The Seeker", "The Undying");
ObservableList<String> WizardClassBox = FXCollections.observableArrayList("Atrificer", "Bladesinging", "Lore Mastery", "School of Abjuration", "School of Conjuration", "School of Divination", "School of Echantment", "School of Evocation", "School of Illusion", "School of Invention", "School of Necromancy", "School of Transmutation", "Technomancy", "Theurgy", "War Magic");
ObservableList<String> AasimarRaceBox = FXCollections.observableArrayList("Protector Aasimar", "Scourge Aasimar", "Fallen Aasimar");
ObservableList<String> DragonbornRaceBox = FXCollections.observableArrayList("Black", "Blue", "Brass", "Bronze", "Copper", "Gold", "Green", "Red", "Silver", "White");
ObservableList<String> DwarfRaceBox = FXCollections.observableArrayList("Duergar Dwarves", "Hill Dwarves", "Mountain Dwarves");
ObservableList<String> ElfRaceBox = FXCollections.observableArrayList("High Elves", "Wood Elves", "Drow(Dark Elves)");
ObservableList<String> GenasiRaceBox = FXCollections.observableArrayList("Air Genasi", "Earht Genasi", "Fire Genasi", "Water Genasi");
ObservableList<String> GnomeRaceBox = FXCollections.observableArrayList("Forest Gnome", "Rock Gnomes", "Deep Gnomes");
ObservableList<String> HalfElfRaceBox = FXCollections.observableArrayList("Wood Half-Elf", "High Half-Elf", "Drow Half-Elf", "Aquatic Half-Elf");
ObservableList<String> HalflingRaceBox = FXCollections.observableArrayList("Ghostwise Halflinf", "Lightfoot Halfling", "Sout Halfling");
ObservableList<Integer> test = FXCollections.observableArrayList(1,2,3);
@FXML
private ResourceBundle resources;
@FXML
private URL location;
@FXML
private Button Continue;
@FXML
private TextField CharacterName;
@FXML
private ChoiceBox<String> Class;
@FXML
private ChoiceBox<String> SubClass;
@FXML
private ChoiceBox<String> Race;
@FXML
private ChoiceBox<String> SubRace;
@FXML
private ChoiceBox<String> Background;
@FXML
private ChoiceBox<Integer> Level;
@FXML
private TextField AC;
@FXML
private ChoiceBox<String> Alignment;
@FXML
private TextField Experience;
@FXML
private ChoiceBox<Integer> str;
@FXML
private ChoiceBox<Integer> dex;
@FXML
private ChoiceBox<Integer> constitution;
@FXML
private ChoiceBox<Integer> intelligence;
@FXML
private ChoiceBox<Integer> wis;
@FXML
private ChoiceBox<Integer> charisma;
@FXML
void Continue(ActionEvent event) {
}
@FXML
void initialize() {
assert Continue != null : "fx:id=\"Continue\" was not injected: check your FXML file 'EnterStats.fxml'.";
assert CharacterName != null : "fx:id=\"CharacterName\" was not injected: check your FXML file 'EnterStats.fxml'.";
assert Class != null : "fx:id=\"Class\" was not injected: check your FXML file 'EnterStats.fxml'.";
assert SubClass != null : "fx:id=\"SubClass\" was not injected: check your FXML file 'EnterStats.fxml'.";
assert Race != null : "fx:id=\"Race\" was not injected: check your FXML file 'EnterStats.fxml'.";
assert SubRace != null : "fx:id=\"SubRace\" was not injected: check your FXML file 'EnterStats.fxml'.";
assert Background != null : "fx:id=\"Background\" was not injected: check your FXML file 'EnterStats.fxml'.";
assert Level != null : "fx:id=\"Level\" was not injected: check your FXML file 'EnterStats.fxml'.";
assert AC != null : "fx:id=\"AC\" was not injected: check your FXML file 'EnterStats.fxml'.";
assert Alignment != null : "fx:id=\"Alignment\" was not injected: check your FXML file 'EnterStats.fxml'.";
assert Experience != null : "fx:id=\"Experience\" was not injected: check your FXML file 'EnterStats.fxml'.";
assert str != null : "fx:id=\"str\" was not injected: check your FXML file 'EnterStats.fxml'.";
assert dex != null : "fx:id=\"dex\" was not injected: check your FXML file 'EnterStats.fxml'.";
assert constitution != null : "fx:id=\"constitution\" was not injected: check your FXML file 'EnterStats.fxml'.";
assert intelligence != null : "fx:id=\"intelligence\" was not injected: check your FXML file 'EnterStats.fxml'.";
assert wis != null : "fx:id=\"wis\" was not injected: check your FXML file 'EnterStats.fxml'.";
assert charisma != null : "fx:id=\"charisma\" was not injected: check your FXML file 'EnterStats.fxml'.";
Class.setItems(ClassBox);
Class.setValue("Bard");
Race.setItems(RaceBox);
Background.setItems(BackgroundBox);
Alignment.setItems(AlignmentBox);
str.setItems(test);
dex.setItems(statBox);
constitution.setItems(statBox);
intelligence.setItems(statBox);
wis.setItems(statBox);
charisma.setItems(statBox);
Level.setItems(statBox);
Race.setValue("Aasimar");
Background.setValue("Acolyte");
Alignment.setValue("Lawful Good");
str.setValue(1);
dex.setValue(1);
constitution.setValue(1);
intelligence.setValue(1);
wis.setValue(1);
charisma.setValue(1);
Level.setValue(1);
}
}
这是整个文件。其中有很多东西,并且所有选择框都会抛出相同的错误。
答案 0 :(得分:0)
检查FXML文件中的身份是否相同