Java FXML错误加载锚点窗格

时间:2017-05-01 18:37:22

标签: java fxml

我正在尝试运行以前运行的Java FX应用程序,并且在加载锚窗格时出错。这个错误是代码的一部分,因为它工作原因我还没有触及,所以我不确定是什么导致它。这是代码:

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);
}

这是我得到的错误:

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

我相信在加载AnchorPane时会抛出错误,但我并不完全确定。谢谢你的帮助!

0 个答案:

没有答案