Exception in Application start method:
Exception in Application start method
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 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(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
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$154(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
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 edu.citytech.view.EmployeeMain.start(EmployeeMain.java:16)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(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$147(WinApplication.java:177)
... 1 more
Exception running application edu.citytech.view.EmployeeMain
Here's the class with the main method, EmployeeMain.java:
package edu.citytech.view;
import edu.citytech.utitlity.GlobalVariables;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
public class EmployeeMain extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("EmployeeView.fxml"));
primaryStage.setScene(new Scene(root));
primaryStage.show();
// * new *
primaryStage.setResizable(false);
primaryStage.setTitle("Employee List");
primaryStage.getIcons().add(new Image(EmployeeMain.class.getResourceAsStream("People.jpg")));
}
public static void main(String[] args) {
if (args.length > 0) {
GlobalVariables.portNumber = (Integer.parseInt(args[0]));
}
launch(args);
}
}
And what fixes this is adding a space to any of the files and saving it, then restarting the Eclipse IDE, and running it again from the IDE. What breaks it is when I run mvn clean and mvn install, and then running the jar file it created. Everyone in my class is having this problem, and the teacher has no idea how to fix it. It just works for some people and it doesn't for others. However this time, this isn't working no matter what I try. Only works in the IDE until I use maven to create a jar. Then it won't work until I modify and save a file, and then restart the IDE. Everything is named properly and it just works and doesn't work randomly. Is this an IDE problem or a project problem?
What can I do so that I can make a jar file that works when it's run?
I figured out how to get it to work. Really annoying but really simple. I'm going to write it here for anyone who is probably finding this page through a search engine.
Right click on project folder > Maven > Update Project...
Update selected project
Right click the project folder and run in local terminal
mvn install
And DO NOT DO MVN CLEAN