简体   繁体   中英

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

When opening the jar file, I can see the list of the fxml's in the main/resource folder, but it is still giving me the "java.lang.NullPointerException: Location is required." error.

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());
            }
        }
    }

You should remove the path instead just use /DatabaseSettingsForm.fxml

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

I suggest a simple try: Find the current directory and then paste (or using absolute path) fxml to that directory:

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);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM