0

everybody !

I'm having some hard time trying to run my JavaFX Application. When I run it inside Eclipse, it works fine, but attempting to run it by means of the jar file, I get the following message error. Am I missing something ?

C:\Users\antonio.a\workspace_cusomization\Checklist\build\deploy\Checklist.jar
java.lang.NullPointerException: Location is required.
        at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
        at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
        at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
        at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
        at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
        at javafx.fxml.FXMLLoader.load(Unknown Source)
        at sidia.org.br.Main.start(Unknown Source)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(Unknown Source)
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source)
        at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

Edited:

The package hierarchy:

sidia.org.br
sidia.org.br.controller
sidia.org.br.view

MainView.fxml file is inside sidia.org.br.view

and Main.class is inside sidia.org.br

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) {

        try {

            AnchorPane root = (AnchorPane)FXMLLoader.load(getClass().getResource("./view/MainView.fxml"));
            Scene scene = new Scene(root, 900, 650);
            scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
            primaryStage.setScene(scene);
            primaryStage.show();

        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}
Android Hunter
  • 361
  • 1
  • 3
  • 8
  • The resource name you are using for your FXML is wrong (or the FXML is not included in the jar file). Show some code and the project layout. – James_D Jan 25 '16 at 15:40
  • @PankajPandey And many others :). If the OP posts more details, we can probably find an exact match for the particular reason the FXML is not found. – James_D Jan 25 '16 at 15:51
  • It works fine on eclipse @James_D. Perhaps so that application is loaded. On the other side, though, running the jar file produces this error. – Android Hunter Jan 25 '16 at 16:31
  • @James_D, I've updated the question. – Android Hunter Jan 25 '16 at 16:37
  • Your resource name includes the path component `.`. That is not a [valid resource name](https://docs.oracle.com/javase/8/docs/technotes/guides/lang/resources.html). So while it might happen to work when your class loader is loading from the file system, there is no guarantee, and it can fail with other class loaders (such as the jar class loader, as you've discovered). – James_D Jan 25 '16 at 16:38
  • It works !!! Thanks, man ! – Android Hunter Jan 25 '16 at 16:47

0 Answers0