title: JavaFX cannot load my FXML, returning null pointer exception
body: <p>I am not sure what the error is I am converting a home project from Swing GUI to JavaFX, using scenebuilder and having a hard time. Please help?
  Details on my error and project structure below:</p>
  <pre><code>Exception in Application start method
  java.lang.reflect.InvocationTargetException
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:568)
      at javafx.graphics@18.0.1/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:465)
      at javafx.graphics@18.0.1/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:568)
      at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1071)
  Caused by: java.lang.RuntimeException: Exception in Application start method
      at javafx.graphics@18.0.1/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:901)
      at javafx.graphics@18.0.1/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
      at java.base/java.lang.Thread.run(Thread.java:833)
  Caused by: java.lang.IllegalStateException: Location is not set.
      at javafx.fxml@18.0.1/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2541)
      at javafx.fxml@18.0.1/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2516)
      at testify.Runtime.App.start(App.java:22)
      at javafx.graphics@18.0.1/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
      at javafx.graphics@18.0.1/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
      at javafx.graphics@18.0.1/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
      at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
      at javafx.graphics@18.0.1/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
      at javafx.graphics@18.0.1/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
      at javafx.graphics@18.0.1/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at javafx.graphics@18.0.1/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
      ... 1 more
  Exception running application testify.Runtime.App
  
  Process finished with exit code 1
  </code></pre>
  <p>here is my project tree:</p>
  <p><a href="https://i.stack.imgur.com/vWpbd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vWpbd.png" alt="enter image description here" /></a></p>
  <p>Here is my main code:</p>
  <pre><code>package testify.Runtime;
  
  import javafx.application.Application;
  import javafx.fxml.FXMLLoader;
  import javafx.scene.Parent;
  import javafx.scene.Scene;
  import javafx.stage.Stage;
  
  import java.io.IOException;
  
  public class App extends Application {
  
   public static void main(String[] args) {
      launch(args);
   }
  
   @Override
   public void start(Stage primaryStage) throws IOException {
      FXMLLoader loader= new FXMLLoader(getClass().getResource(&quot;main.fxml&quot;));
      Parent root = (Parent) loader.load();
      Scene home = new Scene(root);
  
       primaryStage.setTitle(&quot;Testify&quot;);
       primaryStage.setScene(home); 
           primaryStage.show();
      }
  }
  </code></pre>
  <p>Ignore this line for some reason I cannot post a &quot;mostly code&quot; question without having a paragraph written about it on stack overflow and I am not sure why.... never had this issue before on here.</p>