title: Using custom classes in FXML without packages
body: <p>There are several other question regarding this topic, but they all use files placed in packages unlike mine. I have three simple files:</p>
  <ol>
  <li>FXMLtest.java - The main class extending <code>Application</code></li>
  <li>Bean.java - extends <code>Circle</code>. Has an extra property which follows java bean conventions</li>
  <li>view2.fxml</li>
  </ol>
  <p>(all files are in the same folder)<br/>
  I infer (from the stackrace) that the error arises since <code>FXMLLoader</code> is unable to locate <code>Bean</code>, which is on the scene graph in <code>view2.fxml</code>. Perhaps it has something to do with not using a package. If so, I would just like to know why packages are necessary. Given below are the three files and the stack trace.</p>
  <pre><code>import javafx.application.Application;
  import javafx.scene.Scene;
  import javafx.stage.Stage;
  import javafx.fxml.FXMLLoader;
  public class FXMLtest extends Application
  {
      @Override
      public void start(Stage stage) throws Exception
      {
          Scene scene = new Scene(FXMLLoader.load(getClass().getResource(&quot;view2.fxml&quot;)), 300,100);
          stage.setTitle(&quot;JavaFX Example&quot;);
          stage.setScene(scene);
          stage.show();
      }
      public static void main (String[] args){
          launch(args);
      }
  }
  </code></pre>
  <pre><code>import javafx.scene.control.Button;
  import javafx.beans.property.SimpleDoubleProperty;
  public class Bean extends Button{
      private SimpleDoubleProperty foo;
      Bean(){
          super();
      }
      void setFoo(double x){
          foo.set(x);
      }
      double getFoo(){
          return foo.get();
      }
      SimpleDoubleProperty fooProperty(){
          return foo;
      }
  }
  </code></pre>
  <pre><code>&lt;?import javafx.scene.layout.Pane?&gt;
  &lt;?import javafx.scene.control.Button?&gt;
  &lt;?import Bean?&gt;
  &lt;Pane prefHeight=&quot;400.0&quot; prefWidth=&quot;600.0&quot; xmlns:fx=&quot;http://javafx.com/fxml&quot; &gt;
     &lt;children&gt;
        &lt;Button text=&quot;testButton&quot; /&gt;
        &lt;Bean foo=&quot;4.4&quot; text=&quot;button2&quot; /&gt;
     &lt;/children&gt;
  &lt;/Pane&gt;
  </code></pre>
  <pre><code>Exception in Application start method
  Exception in thread &quot;JavaFX BlueJ Helper&quot; 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$155(LauncherImpl.java:182)
      at java.lang.Thread.run(Thread.java:748)
  Caused by: javafx.fxml.LoadException: 
  /C:/java/view2.fxml
  
      at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
      at javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2848)
      at javafx.fxml.FXMLLoader.processImport(FXMLLoader.java:2692)
      at javafx.fxml.FXMLLoader.processProcessingInstruction(FXMLLoader.java:2661)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2517)
      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 FXMLtest.start(FXMLtest.java:10)
      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)
      ... 1 more
  Caused by: java.lang.ClassNotFoundException
      at javafx.fxml.FXMLLoader.loadType(FXMLLoader.java:2899)
      at javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2846)
      ... 20 more
  </code></pre>