title: Error loading fxml files from a folder other than the bin folder
body: <p>I am a fairly new java programmer. I only have about five weeks of experience, starting from zero, and I am having problems getting javafx fxml files created in Scene Builder to load correctly if they are not in the same folder as the controller classes.</p>
  
  <p>I am using </p>
  
  <pre><code>Win7x64 running jre7x86 for this build
  
  Eclipse Juno Service Release 1
  Build id: 20120920-0800
  
  jre version 1.7.0_07
  
  javaFx version 2.2.1-b03
  
  SceneBuilder version 1.0-b50
  </code></pre>
  
  <p>My scene loader code is</p>
  
  <pre><code>private static final String RESOURCE_PATH = "/resources/";
  public static Stage buildStage(@SuppressWarnings("rawtypes") Class pClass,
           String stageTitle, String resourceLocation)
     {
        Stage temp = new Stage();
        Pane page = null;
        try
        {
           page = FXMLLoader.load(pClass.getResource(RESOURCE_PATH + resourceLocation), null,
                 new JavaFXBuilderFactory());
        }
        catch (IOException e)
        {
           e.printStackTrace();
        }
        Scene scene = new Scene(page);
        temp.setScene(scene);
        temp.setTitle(stageTitle);
        temp.setResizable(false);
        return temp;
     }
  </code></pre>
  
  <p>I know that the project directory is the <code>/workspace/projectName/</code> so theoretically the loader should be able to find the files if it's given a relative path right? The error I'm getting is </p>
  
  <pre><code>Exception in Application start method
  Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
      at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
      at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
      at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
      at java.lang.Thread.run(Unknown Source)
  Caused by: java.lang.NullPointerException: Location is required.
      at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2737)
      at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2721)
      at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2707)
      at outofunit.system.StageFactory.buildStage(StageFactory.java:32)
      at outofunit.desktop.ArcMaster.start(ArcMaster.java:28)
      at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
      at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:206)
      at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:173)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
      at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
      ... 1 more
  </code></pre>
  
  <p>I've tried giving the loader an absolute path as well but it just isn't accepting anything that isn't directly in the same directory. I'm grasping at straws here trying to figure this out. </p>
  
  <p>I've tried to research this on my own but I haven't gotten much, the few answers on here that seemed similar didn't seem to help, that or I am too dense and/or inexperienced to make sense of them. They are <a href="https://stackoverflow.com/questions/10411164/javafx-2-0-loading-fxml-files-with-event-handlers-fails">JavaFX 2.0 loading fxml files with event handlers fails</a> and <a href="https://stackoverflow.com/questions/10405288/javafx-2-0-fxml-resource-loading-error">JavaFX 2.0 FXML resource loading error</a></p>
  
  <p>A buddy of mine was able to overcome this problem by using this code </p>
  
  <pre><code>public void load(String pFileName, Stage pStage, String pTitle)
     {
        String fName = RESOURCE_PATH + pFileName;
  
        try
        {
           String externalForm = getClass().getResource(fName)
              .toExternalForm();
  
           InputStream inStream = new URL(externalForm).openStream();
  
           FXMLLoader loader = new FXMLLoader();
           Pane p = (Pane)loader.load(inStream);
  
           pStage.setTitle(pTitle);
           pStage.setScene(new Scene(p));
  
           mWindowControl = loader.getController();
           mWindowControl.setUp(pStage);
  
           pStage.show();
        }
        catch (Exception e)
        {
           e.printStackTrace();
        }
     }
  </code></pre>
  
  <p>The biggest difference and the reason why I haven't been using his code is because my root pane is an Anchor pane instead of a normal pane, and his way URL instream forces a normal pane. Am I at fault for not using a normal pane as my base? I would love any help or input you guys can give. Thank you.</p>
  
  <p>Edit: So I've been working on this problem and the error message has changed.</p>
  
  <p>I changed the code to this</p>
  
  <pre><code>private final String RESOURCE_PATH = "resources/";
  public void load(String pFileName, Stage pStage, String pTitle)
     {
        String fName = RESOURCE_PATH + pFileName;
  
        Pane page = null;
  
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(fName));
  
        try
        {
           page = (Pane) fxmlLoader.load();
        }
        catch (IOException exception)
        {
           throw new RuntimeException(exception);
        }
  
        Scene scene = new Scene(page);
        pStage.setScene(scene);
        pStage.setTitle(pTitle);
  
        mWindowControl = fxmlLoader.getController();
        mWindowControl.setUp(pStage);
  
        pStage.show();
     }
  </code></pre>
  
  <p>but the error I'm now getting is </p>
  
  <pre><code>java.lang.IllegalStateException: Location is not set.
      at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2021)
      at outofunit.desktop.WindowLoader.load(WindowLoader.java:136)
      at outofunit.desktop.WindowLoader.load(WindowLoader.java:62)
      at outofunit.desktop.ArcMaster.start(ArcMaster.java:30)
      at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
      at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:206)
      at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:173)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
      at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>I don't understand how the location is not being set</p>