title: Loading multiple FXML-files fails when controllers are defined
body: <p>I know this question is asked many times, but I can't find a solution, that works for me (actually I can't even see what I am doing wrong).</p>
  
  <p>The basic idea is to load GUI-components when needed. So I structured the GUI in various FXML-Files and implemented controller-classes. Both - FXML-files and classes - are stored in the same package but ther is a package for every component. Every FXML-file is loading and added to the GUI as long as I do not define the controller-class within the FXML-file (fx:controller). If it is defined I will get a LoadException.</p>
  
  <p>For a better understanding here is my code (simplified):</p>
  
  <p>Main.java:</p>
  
  <pre><code>package application;
  
  import application.a.ControllerA;
  import javafx.application.Application;
  import javafx.event.ActionEvent;
  import javafx.fxml.FXML;
  import javafx.fxml.FXMLLoader;
  import javafx.scene.Parent;
  import javafx.scene.Scene;
  import javafx.scene.control.Button;
  import javafx.scene.layout.BorderPane;
  import javafx.stage.Stage;
  
  public class Main extends Application
  {
      // Button aus MainLayout.fxml
      @FXML
      private Button button;
  
      @Override
      public void start(Stage primaryStage)
      {
          try
          {
              BorderPane root = new BorderPane();
  
              Parent contentMain = FXMLLoader.load(getClass().getResource("MainLayout.fxml"));
              ControllerA contentA = new ControllerA(root);
  
              root.setTop(contentA.getContent());
              root.setCenter(contentMain);
  
              Scene scene = new Scene(root, 400, 400);
              scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
              primaryStage.setScene(scene);
              primaryStage.show();
          }
          catch (Exception e)
          {
              e.printStackTrace();
          }
      }
  
      public static void main(String[] args)
      {
          launch(args);
      }
  
      // Event-Handler für den Button -&gt; funktioniert!
      @FXML
      public void buttonClicked(ActionEvent e)
      {
          if (!button.getText().equals("NEW"))
          {
              button.setText("NEW");
          }
          else
          {
              button.setText("OLD");
          }
      }
  }
  </code></pre>
  
  <p>This class is also a controller for the following layout (and it works fins so far):</p>
  
  <p>MainLayout.fxml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import javafx.scene.control.*?&gt;
  &lt;?import java.lang.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  &lt;?import javafx.scene.layout.GridPane?&gt;
  
  &lt;Pane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Main"&gt;
     &lt;children&gt;
        &lt;Button fx:id="button" mnemonicParsing="false" onAction="#buttonClicked" text="Button" /&gt;
     &lt;/children&gt;
  &lt;/Pane&gt;
  </code></pre>
  
  <p>In a sub-package (called a) of <code>application</code> you will find this:</p>
  
  <p>ControllerA.java:</p>
  
  <pre><code>package application.a;
  
  import java.net.URL;
  
  import javafx.event.ActionEvent;
  import javafx.fxml.FXML;
  import javafx.fxml.FXMLLoader;
  import javafx.scene.Parent;
  import javafx.scene.control.Button;
  import javafx.scene.layout.BorderPane;
  
  public class ControllerA
  {
      private Parent content;
  
      @FXML
      private Button buttonA;
  
      public ControllerA(BorderPane root)
      {
          String sceneFile = "A.fxml";
          URL url = null;
          try
          {
              url = getClass().getResource(sceneFile);
              content = FXMLLoader.load(url);
          }
          catch (Exception ex)
          {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
          }
      }
  
      public Parent getContent()
      {
          return content;
      }
  
      @FXML
      public void clickedA(ActionEvent e)
      {
          buttonA.setText("Clicked already");
      }
  }
  </code></pre>
  
  <p>A.fxml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import javafx.scene.control.*?&gt;
  &lt;?import java.lang.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  &lt;?import javafx.scene.layout.GridPane?&gt;
  
  &lt;Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.a.ControllerA"&gt;
     &lt;children&gt;
        &lt;Button fx:id="buttonA" layoutX="274.0" layoutY="188.0" mnemonicParsing="false" onAction="#clickedA" text="A" /&gt;
     &lt;/children&gt;
  &lt;/Pane&gt;
  </code></pre>
  
  <p>And this is, where it all went wrong:</p>
  
  <pre><code>javafx.fxml.LoadException: 
  /Z:/BachelorArbeit/Projektdateien/Entwicklung/EclipseWorkspace/Sandbox/bin/application/a/A.fxml:8
  
      at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
      at javafx.fxml.FXMLLoader.access$700(FXMLLoader.java:103)
      at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:932)
      at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)
      at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
      at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)
      at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
      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 application.a.ControllerA.&lt;init&gt;(ControllerA.java:26)
      at application.Main.start(Main.java:35)
      at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
      at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
      at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$148(WinApplication.java:191)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: java.lang.InstantiationException: application.a.ControllerA
      at java.lang.Class.newInstance(Class.java:427)
      at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
      at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:927)
      ... 23 more
  Caused by: java.lang.NoSuchMethodException: application.a.ControllerA.&lt;init&gt;()
      at java.lang.Class.getConstructor0(Class.java:3082)
      at java.lang.Class.newInstance(Class.java:412)
      ... 25 more
  </code></pre>
  
  <p>I've tried to fiddle around with the path-String like</p>
  
  <ul>
  <li>"./a/A.fxml" </li>
  <li>"/application/a/A.fxml" </li>
  <li>"A.fxml" </li>
  <li>"a/A.fxml"</li>
  <li>...</li>
  </ul>
  
  <p>but nothing worked. I would be quite relieved if someone can halp me with this problem.</p>