Netbeans上的JavaFX

3

我有一个JavaFX应用程序,在我的电脑上运行得很好,但在我的笔记本电脑上根本不起作用。 我认为我的电脑和笔记本电脑上的设置是相同的:

  • NetBeans 7.4
  • Java 1.7.0_45

这是开始方法:

@Override
public void start(Stage stage) throws Exception {
    FXMLLoader loader = new FXMLLoader();

    Parent fxmlRoot = (Parent) loader.load(new FileInputStream(new File(
            "src\\com\\gasstation\\views\\main-layout.fxml")));

    Scene scene = new Scene(fxmlRoot);

    stage.setScene(scene);
    stage.show();

    GasStationXmlParser parser = new GasStationXmlParser("src\\config.xml");
    newGasStation = parser.getGasStations();

    MainController mainController = loader.getController();

    for (GasStation station : newGasStation) {
        mainController.setConfigData(station);
    }

    startAllGasStations();
}
当我尝试运行应用程序时,出现以下错误信息:
java.lang.NullPointerException
at javafx.fxml.FXMLLoader.equals(FXMLLoader.java:1855)
at javafx.fxml.FXMLLoader.isCyclic(FXMLLoader.java:1867)
at javafx.fxml.FXMLLoader.access$2200(FXMLLoader.java:66)
at javafx.fxml.FXMLLoader$IncludeElement.constructValue(FXMLLoader.java:935)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:565)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2348)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2164)
at com.gasstation.main.Main.start(Main.java:27)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:216)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67)
at java.lang.Thread.run(Thread.java:744)
Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
    at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
    at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
    at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.NullPointerException
    at javafx.stage.Window.impl_visibleChanging(Window.java:816)
    at javafx.stage.Stage.impl_visibleChanging(Stage.java:922)
    at javafx.stage.Window$9.invalidated(Window.java:690)
    at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:127)
    at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:161)
    at javafx.stage.Window.setShowing(Window.java:779)
    at javafx.stage.Window.show(Window.java:794)
    at javafx.stage.Stage.show(Stage.java:229)
    at com.gasstation.main.Main.start(Main.java:37)
    at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
    at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:216)
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17)
    at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67)
    ... 1 more
Java Result: 1

我从中无法解决任何问题...

有什么想法吗?


2
展示 com.gasstation.main.Main.start(Main.java:27) - user1907906
我已经添加了com.gasstation.main.Main.start。 - Yoni Levy
src\\com\\gasstation\\views\\main-layout.fxml 文件是否存在且为有效的 JavaFX 文件? - user1907906
是的,两个都可以。它在我的电脑上运行良好,并且我使用Scene Builder创建了它。 - Yoni Levy
1个回答

0

Parent fxmlRoot = (Parent) loader.load(new FileInputStream(new File("src\com\gasstation\views\main-layout.fxml")));之前尝试调用loader.setLocation(Main.class.getResource(/com/gasstation/views/main-layout.fxml));


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,