When I tried to populate my choiceBox with an array of strings in the start method, I got a NullPointerException. I tried to use methods found online but nothing is working
@FXML
private ChoiceBox<String> enterState;
@FXML
private ChoiceBox<Integer> enterYearJoined;
@FXML
private CheckBox enterIsHeActive;
@FXML
private Button enterStudentInfo;
/*What the ChoiceBox needs to contain
*
* "AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA",
"KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH",
"NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX",
"UT", "VT", "VA", "WA", "WV", "WI", "WY"*/
public void start(Stage primaryStage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("\\CreateNewStudent.fxml"));
Scene scene = new Scene(root,500,300);
primaryStage.setScene(scene);
primaryStage.show();
enterState.setItems(FXCollections.observableArrayList("AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA",
"KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH",
"NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX",
"UT", "VT", "VA", "WA", "WV", "WI", "WY"));
} catch(Exception e) {
System.out.println("ERROR IN MAIN");
e.printStackTrace();
}
}
It gives me an error as soon as I reach the enterState method. Did I make a stupid mistake? Did I not put this in the right place? help