I have the following code to call Scene in my Eclipse.

public class Login extends Application 

{

public static final String ICON_IMAGE_LOC = "/icons/Message.png";
@Override
    public void start(Stage primaryStage) 

    {
        setStage(primaryStage);



        try 

        {

            FXMLLoader loader = new FXMLLoader(this.getClass().getResource("/FXML/Login.fxml"));
            Parent root = loader.load();

            Scene scene = new Scene(root);
            primaryStage.setTitle("Login");
            primaryStage.getIcons().add(new javafx.scene.image.Image(ICON_IMAGE_LOC));
            primaryStage.setScene(scene);
            primaryStage.setResizable(false);

            primaryStage.show();


        } 

        catch (IOException e) 

        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

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

In Eclipse it opens normally. But when I export the JAR file and execute, the following error occurs:

C:\Users\Gabriel Augusto\Desktop>java -jar Dialog.jar Exception in Application start method Exception in thread "main" 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 org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61) 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$159(LauncherImpl.java:182) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.IllegalStateException: Location is not set. at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409) at application.Login.start(Login.java:47) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$166(LauncherImpl.java:863) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$179(PlatformImpl.java:326) at com.sun.javafx.application.PlatformImpl.lambda$null$177(PlatformImpl.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$178(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$152(WinApplication.java:177) ... 1 more

The files in my project are arranged as follows:

enter image description here

Why is this error occurring? Thanks.

0 Answers