簡體   English   中英

對jar的IntelliJ給出了“java.lang.NullPointerException:Location is required”。

[英]IntelliJ to jar is giving “java.lang.NullPointerException: Location is required.”

打開jar文件時,我可以在main / resource文件夾中看到fxml的列表,但它仍然給我“java.lang.NullPointerException:Location is required”。 錯誤。

package fxproject;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class ApplicationSplashScreen extends Application
    {
        Stage window;
        public static void main(String args[])
        {
            launch(args);
        }

        @Override
        public void start(Stage primaryStage) throws Exception
        {
            window = primaryStage;
            loadDatabaseScreen();
             window.close();
        }

        private void loadDatabaseScreen()
        {
            try
            {
                Stage stage = new Stage();
                Parent root = FXMLLoader.load(getClass().getResource("../main/resources/DatabaseSettingsForm.fxml"));
                Scene scene = new Scene(root);
                stage.setScene(scene);
                stage.sizeToScene();
                stage.show();
            }
            catch(Exception e)
            {
                new OrchidAlertBox("Error",e.toString());
            }
        }
    }

您應該刪除路徑,而只需使用/DatabaseSettingsForm.fxml

Stage stage = new Stage();
Parent root = FXMLLoader.load(getClass().getResource("/DatabaseSettingsForm.fxml"));

我建議一個簡單的嘗試:找到當前目錄,然后粘貼(或使用絕對路徑) fxml到該目錄:

public static void main(String args[])
    {
        //1. find current working dirrectory
        System.out.println(new File(".").getAbsolutePath());
        //2. paste fxml's to this directory or modify ../main/.. to absolute path
        //3. run program again?
        launch(args);
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM