Netbeans 上的 JavaFX
Posted
技术标签:
【中文标题】Netbeans 上的 JavaFX【英文标题】:JavaFX on Netbeans 【发布时间】:2013-11-07 19:07:51 【问题描述】:我有一个 javafx 应用程序,它在我的 PC 上运行良好,但在我的笔记本电脑上根本无法运行 我相信我的 PC 和笔记本电脑上的设置相同:
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
我无法解决任何问题......
有什么想法吗?
【问题讨论】:
告诉我们com.gasstation.main.Main.start(Main.java:27)
我添加了 com.gasstation.main.Main.start
src\\com\\gasstation\\views\\main-layout.fxml
是否存在,它是一个有效的 JavaFX 文件吗?
两者都是。它在我的 PC 上运行,我使用 Scene Builder 创建了它
【参考方案1】:
尝试在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));
【讨论】:
以上是关于Netbeans 上的 JavaFX的主要内容,如果未能解决你的问题,请参考以下文章
Sublime Text 导入 php 类有啥解决方案吗?类似于 Netbeans 上的“快速导入”的东西?
在 Linux (Mageia) 上的 NetBeans 中从 Java 应用程序连接到 MariaDB
Mac OS X 10.7.5 上的 NetBeans 7.3.1 找不到源文件夹(使用现有源打开项目)