Title: JavaFX Exception in Application start method (java.lang.IllegalStateException: Location is not set.)
Tags: java;javafx;runtime-error
Question: I tried moving my fxml file around but I can't seem to get the right path to my file. Also does my controller have to be in the same package as my fmxl file. I read online I should put my fxml file into the resources folder and that's what I did but it's still not working. My controller is in the UI folder should I move that to the resource folder?

```public class Main extends Application{

    public Main() {

    }
    private static ArgumentParser argumentParser;
    private static Stage primaryStage;
    private static ArgumentResponder argumentResponder;
    private static UncaughtExceptionLogger uncaughtExceptionLogger;
    private static Settings settings;
    /**
     * The main method, for starting the application.
     *
     * <p&gt;See {@link Argument} for the supported arguments.</p&gt;
     *
     * @param args arguments given when starting KouChat.
     */
    public static void main(String[] args){

        argumentParser = new ArgumentParser(args);
        argumentResponder = new ArgumentResponder(argumentParser);

        if (!argumentResponder.respond()) {
            return;
        }

        new LogInitializer(argumentParser.hasArgument(Argument.DEBUG));
        // Initialize as early as possible to catch all exceptions
         uncaughtExceptionLogger = new UncaughtExceptionLogger();

         settings = loadSettings(argumentParser);

        launch(args);
    }
    private static Settings loadSettings(final ArgumentParser argumentParser) {
        final Settings settings = new Settings();

        final ArgumentSettingsLoader argumentSettingsLoader = new ArgumentSettingsLoader();
        argumentSettingsLoader.loadSettings(argumentParser, settings);

        final PropertyFileSettingsLoader propertyFileSettingsLoader = new PropertyFileSettingsLoader();
        propertyFileSettingsLoader.loadSettings(settings);

        return settings;
    }
    @Override
    public void start(Stage primaryStageObj) throws Exception{
        primaryStage = primaryStageObj;
        System.out.println(getClass().getResource("Chat.fxml"));
        FXMLLoader loader = new FXMLLoader(getClass().getResource("Chat.fxml"));
        ChatController pls = new ChatController(argumentParser, settings, uncaughtExceptionLogger);
        loader.setController(pls);
        pls.setStage(primaryStage);
        Parent root = loader.load();
        primaryStage.setTitle("Flake");
        primaryStage.setScene(new Scene(root, 959,583  ));
        primaryStage.setResizable(false);
        primaryStage.show();
        primaryStage.setResizable(false);
        primaryStage.setOnCloseRequest(e -&gt; Platform.exit());


    }
}
```

This is my project path to help see where I am going wrong



The error message I am receiving when running my code.

```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$154(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:748)
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 net.usikkert.kouchat.Main.start(Main.java:71)
    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 net.usikkert.kouchat.Main
```

Comment: @James_D I added the leading / but I still get the same error. How do i check if my resources folder is configured properly.

Comment: When i do this:  `System.out.println(getClass().getResource("/Chat.fxml"));` I still get null

Comment: @James_D i am still new to this what exactly is the build folder and how do i get to this. Are you talking about my target folder? Because if so I don't see my fxml files in there just my regular classes and interfaces

Comment: @James_D Yes i see the other contents of my resources folder. Mabye its because im converting from swing to javafx?

Comment: @James_D I'm using intellij, can i just move my fxml to my main folder and try to run it from there? I dont know how to configure which files are deployed by the resources folder

Comment: Okay Thank you so much for your help!

Comment: @FruitCode are you using maven? This error often occurs when you are using maven and even if you put the `.fxml` file right next to the Main class or wherever you load it, it doesn't find it. If this is the case I think I know how to solve it. If you are not using maven then it should work relative simply. Probably you should play with the path, like adding a "/" or "." or carefully spelling the file's name. In IntelliJ if you are holding Ctrl and mouseover the "Chat.fxml" it should be highlighted and  "clickable" if it is not, then there is a problem.

Comment: Assuming your `resources` folder is configured as expected (i.e. that the contents go to the root of the classpath), your `Chat.fxml` file will be in the classpath root. `getClass().getResource()` searches relative to the current class, so it will look in the `net.usikkert.kouchat` package. To search in the root of the classpath, use `getClass().getResource("/Chat.fxml")` (with a leading `/`).

Comment: Check the build folder and see if `Chat.fxml` is there, and if so, which folder it is in.

Comment: Target folder sounds right. (The folder names depend on the IDE/build tool.) The folder that has the hierarchy where the class files end up. Are the other contents of the resources folder deployed there?

Comment: So clearly somewhere you must have configured which files (or types of files) are deployed from the resources folder. I'd right-click on it and look for a configuration/properties option. This just looks IDE specific.

Comment: I don't know: I don't use IntelliJ. But it seems that if you have a separate resources folder for resources that are not compiled, that would be the natural place to put an FXML file.



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 12, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2018:00:03/26/18', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<java><javafx><runtime-error>', 'Title': 'JavaFX Exception in Application start method (java.lang.IllegalStateException: Location is not set.)', 'ViewCount': 3162, 'id': 49497409, 'user_AboutMe': '', 'user_AccountId': 13225769.0, 'user_DisplayName': 'forests', 'user_Reputation': 195.0, 'user_Views': 64.0, 'user_id': 9550901.0}}