gpt4 book ai didi

java - 将 URL 设置为我的 .fxml

转载 作者:行者123 更新时间:2023-12-02 12:21:40 25 4
gpt4 key购买 nike

我无法链接我的 .fxml 文件。另外,我是java新手,还没有弄清楚如何链接东西等等。当然,我尝试在谷歌上搜索答案,但没有得到太多结果。

这是我的文件

public class loadingWindowTest extends Application{

public static void main(String[] args){
launch(args);
}

@Override
public void start(Stage loadingWindowStage) throws Exception {
try{
FXMLLoader loadLoadingWindow = new FXMLLoader();
loadLoadingWindow.setLocation( getClass().getResource("de.skullbro.pong.windows.loadingWindow.loadingWindow.fxml"));
loadLoadingWindow.setController( "de.skullbro.pong.windows.loadingWindow.loadingWindowController");
Parent root = loadLoadingWindow.load();

Scene scene = new Scene(root,(getSystemInformation.screenWidth * 0.5), (getSystemInformation.screenHeight * 0.5));

loadingWindowStage.setScene(scene);
loadingWindowStage.show();
}
catch(Exception e){
if(debug.DebugInformation()){
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Fehler");
alert.setHeaderText("");
alert.setContentText(e.toString());
alert.show();
}
else{
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Upps...");
alert.setHeaderText("Something went wrong.");
alert.setContentText("Please try to restart your Game. If this doesn't fix it contact the Developers");
alert.show();
}
}

}}

我的错误是:位置未设置

我做错了什么?我不确定我的 loadingWindow.setlocation()

<小时/>

这也不起作用:

loadLoadingWindow.setLocation(getClass().getResource("de/skullbro/pong/windows/loadingWindow/loadingWindow.fxml"));

这是我的树的图像

mytree in eclipse

她是我收到的错误 nullpointerException:

java.lang.NullPointerException
at de.skullbro.pong.windows.loadingWindow.loadingWindowTest.start(loadingWindowTest.java:26)
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)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Unknown Source)

最佳答案

getResource() 需要一个路径,而不是包列表:

所以你可以更改为:

loadLoadingWindow.setLocation(getClass().getResource("loadingWindow.fxml"));
<小时/>

Linked to

关于java - 将 URL 设置为我的 .fxml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45731253/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com