javafx - 将 fxml 文件加载到 BorderPane
问题描述
如何将 fxml 文件加载到边界窗格中?我想像这样加载它并且它不工作,你可以看到我在代码下面出现的错误
FXMLLoader loader2 = new FXMLLoader();
path = getClass().getResource("CompanyHome.fxml");
try {
loader2.setLocation(path);
//whiteBorderPane = (BorderPane) loader2.load();
whiteBorderPane.setCenter(loader2.load());
} catch (IOException e){
System.out.println("Not found: " + path);
e.printStackTrace();
}
错误:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at gui.CompanyMainC.initializeView(CompanyMainC.java:90)
at gui.CompanyMainC.start(CompanyMainC.java:70)
at
com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
... 1 more
Exception running application gui.CompanyMainC
如果有人知道在 dorderpane 中加载 fxml 文件的另一种方法,我会很高兴
解决方案
推荐阅读
- regex - 可以将后视与非固定长度模式结合使用吗?
- sed - sed 删除与包含斜杠的变量值匹配的字符串
- c# - 如何在 C# 中从 ASP.NET 调用 office-365 版本的 Excel?
- c# - 如果单击切换,如何将我的 RadzenTextBox 设置为 String.Empty
- java - 跨模块共享测试资源
- c# - 动态多态性/实例创建混乱
- c - 我的二叉搜索树 c 程序有问题。我使用的是中序遍历。为什么只打印根节点?
- go - 使用 golang 以与 openssl genrsa 相同的方式获取 RSA 密钥
- azure-logic-apps - 从 Azure 逻辑应用连接到 Azure SQL 服务器时出错
- amazon-web-services - 无法在 Internet 上访问用于服务发现的公共 DNS 命名空间