有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java将URL设置为my。fxml

我无法链接我的。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();   
        }
    }

}}

我的错误是: 未设置动作

我做错了什么? 我不确定我的加载窗口。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)

共 (1) 个答案

  1. # 1 楼答案

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

    因此,您可以改为:

    loadLoadingWindow.setLocation(getClass().getResource("loadingWindow.fxml"));
    

    ^{}