title: JavaFX web deployment: FXMLLoader NullPointerException
body: <p>I wanted to try JavaFX web browser deployment, so I started a very simple test project using the IntelliJ community edition 14.0.2 JavaFX Application template. Here's the code: (<strong>NO</strong> plugin, external library or maven)</p>
  
  <p>Main.java</p>
  
  <pre><code>@Override
  public void start(Stage primaryStage) throws Exception{
      Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
      primaryStage.setTitle("Hello World");
      primaryStage.setScene(new Scene(root, 300, 275));
      primaryStage.show();
  }
  
  
  public static void main(String[] args) {
      launch(args);
  }
  </code></pre>
  
  <p>Controller.java (attached to sample.fxml)</p>
  
  <pre><code>@FXML
  private TextField textField;
  
  @FXML
  private Label label;
  
  @FXML
  private void setLabelText() {
      label.setText(textField.getText());
  }
  </code></pre>
  
  <p>sample.fxml (Layout file)</p>
  
  <pre><code>&lt;VBox alignment="TOP_CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
        prefHeight="400.0" prefWidth="600.0" spacing="20.0" xmlns="http://javafx.com/javafx/8"
        xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller"&gt;
     &lt;padding&gt;
        &lt;Insets bottom="20.0" left="20.0" right="20.0" top="20.0"/&gt;
     &lt;/padding&gt;
     &lt;TextField fx:id="textField" onAction="#setLabelText"/&gt;
     &lt;Label fx:id="label" text="Label"&gt;
        &lt;font&gt;
           &lt;Font size="96.0"/&gt;
        &lt;/font&gt;
     &lt;/Label&gt;
  &lt;/VBox&gt;
  </code></pre>
  
  <p>Now when I build the app as JAR, it runs without any problem.
  However, when I build it using the pre-defined "JavaFXApp" artifact, it generates one html, one jnlp and one jar. When I open up the html in my web browser (Firefox Nightly 64bit) It gives me the following error:</p>
  
  <pre><code>java.lang.NullPointerException: Location is required.
      at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
      at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
      at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
      at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
      at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
      at javafx.fxml.FXMLLoader.load(Unknown Source)
      at sample.Main.start(Main.java:13)
      at com.sun.javafx.applet.FXApplet2$2.run(Unknown Source)
      at com.sun.javafx.application.PlatformImpl.lambda$null$164(Unknown Source)
      at com.sun.javafx.application.PlatformImpl$$Lambda$45/1838209255.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(Unknown Source)
      at com.sun.javafx.application.PlatformImpl$$Lambda$44/1604839423.run(Unknown Source)
      at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.lambda$null$141(Unknown Source)
      at com.sun.glass.ui.win.WinApplication$$Lambda$36/982109627.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.NullPointerException: Location is required.
      at com.sun.javafx.applet.FXApplet2$2.run(Unknown Source)
      at com.sun.javafx.application.PlatformImpl.lambda$null$164(Unknown Source)
      at com.sun.javafx.application.PlatformImpl$$Lambda$45/1838209255.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(Unknown Source)
      at com.sun.javafx.application.PlatformImpl$$Lambda$44/1604839423.run(Unknown Source)
      at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.lambda$null$141(Unknown Source)
      at com.sun.glass.ui.win.WinApplication$$Lambda$36/982109627.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  Caused by: java.lang.NullPointerException: Location is required.
      at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
      at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
      at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
      at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
      at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
      at javafx.fxml.FXMLLoader.load(Unknown Source)
      at sample.Main.start(Main.java:13)
      ... 11 more
  </code></pre>
  
  <p>The relevant line of code seems to be</p>
  
  <pre><code>Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
  </code></pre>
  
  <p>However this same line of code works just fine when built and opened as single standalone JAR!
  Any idea on why the error occurs or how to fix it?</p>