I am trying to run a previously running Java FX application and am getting an error loading the anchor pane. This error is in part of the code that I haven't touched since it was working so I'm not sure what caused it. Here is the code:
public class Main extends Application {
private Stage primaryStage;
private Composition composition;
@Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
mainWindow();
}
public void mainWindow(){
try {
FXMLLoader loader = new FXMLLoader(Main.class.getResource("MainWindowView.fxml"));
AnchorPane pane = (AnchorPane) loader.load();
MainWindowController mainWindowController = loader.getController();
mainWindowController.setMain(this);
mainWindowController.setCompositon(composition);
Scene scene = new Scene(pane);
primaryStage.setScene(scene);
primaryStage.show();
mainWindowController.run();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
And here is the error I am getting:
javafx.fxml.LoadException:
/Users...bin/application/MainWindowView.fxml:11
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at application.Main.mainWindow(Main.java:27)
at application.Main.start(Main.java:20)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162
(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175
(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173
(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174
(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run
(InvokeLaterDispatcher.java:95)
Caused by: java.lang.NullPointerException
at application.MainWindowController.<init>(MainWindowController.java:57)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance
(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance
(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:927)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute
(FXMLLoader.java:971)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement
(FXMLLoader.java:744)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
... 10 more
I believe the error is being thrown while loading the AnchorPane, but I'm not completely sure. Thanks for any help!