0

I'm writting a program in Java and I'm using JavaFX for the GUI. Until today i've using javafx stand alone to code and everything runs smoothly. I've decided to start using maven and now the project doesnt compile nor does it run or execute.

    Exception in Application start method
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
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$155(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException: Location is required.
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
    at main.java.Main.start(Main.java:19)
    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)
    ... 1 more
Exception running application main.java.Main

This is my main class:

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

@Override
public void start(Stage primaryStage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getResource("../fxml/AuthenticationForm.fxml"));
    primaryStage.setTitle("Gym Master 1000");
    primaryStage.setScene(new Scene(root));
    primaryStage.show();
    primaryStage.setResizable(false);
    primaryStage.centerOnScreen();

    root.getChildrenUnmodifiable();
}

I have used maven on other projects but never with javafx. What do i do?

  • See https://stackoverflow.com/questions/34755630/javafx-location-is-not-set-error You should not use `..` in the resource name when you are packaging as a jar file. – James_D Jul 28 '17 at 12:08

1 Answers1

0

First of all be sure that your .fxml file is in the same directory as the main class, and use the complete path in the .getResource("complete path") and not getResource("../fxml/AuthenticationForm.fxml")) because .. ins´t valid.

Also you can use :

Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("completePATH"));

Instead:

Parent root = FXMLLoader.load(getClass().getResource("../fxml/AuthenticationForm.fxml"));

For more information, you can look here and here. Thanks to James_D from his information.

F.Stan
  • 553
  • 1
  • 10
  • 23
  • 1
    [`..` is not a valid resource name](https://docs.oracle.com/javase/8/docs/technotes/guides/lang/resources.html), so I don't think this will fix it. – James_D Jul 28 '17 at 12:09
  • After some research, you are right, "../fxml/AuthenticationForm.fxml" is not a valid name, I will edit my question immediately.Thanks. – F.Stan Jul 28 '17 at 12:28