title: javafx.scene.layout.Pane cannot be cast to javafx.fxml.FXMLLoader
body: <p>I'm having trouble when trying to switch from a scene to another scene. The scenario is this:</p>
  
  <p><strong>Current View and Controller</strong>: <code>login.fxml</code> and <code>LoginController</code></p>
  
  <p><strong>Next step View and Controller</strong>: <code>loggedWindow.fxml</code> and <code>UserPanelController</code>.</p>
  
  <hr>
  
  <p>Now, I'm in <code>LoginController</code> and trying to switch the scene to <code>loggedWindow.fxml</code> sending to <code>UserPanelController</code> a parameter, but when I'm using my code I get:</p>
  
  <pre><code>javafx.scene.layout.Pane cannot be cast to javafx.fxml.FXMLLoader
  </code></pre>
  
  <h2>LoginController:</h2>
  
  <pre><code>FXMLLoader loggedWindow = null;
  loggedWindow = FXMLLoader.load(getClass().getResource("loggedWindow.fxml")); // here crashes!
  Pane root = loggedWindow.load();
  
  UserPanelController controller = loggedWindow.getController();
  controller.initData(customer);
  
  Stage switchScene = (Stage)((Node)event.getSource()).getScene().getWindow();
  switchScene.setResizable(false);
  switchScene.setTitle("Welcome " + customer.FirstName + " " + customer.LastName);
  switchScene.setScene(new Scene(root, 800, 500));
  
  switchScene.show();
  </code></pre>
  
  <h2>LoggedWindow.fxml</h2>
  
  <pre><code>&lt;Pane maxHeight="500.0" maxWidth="800.0" minHeight="500.0" minWidth="800.0" prefHeight="500.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Main.UserPanelController"&gt;
     &lt;children&gt;
        &lt;ToolBar prefHeight="40.0" prefWidth="831.0"&gt;
          &lt;items&gt;
           .
           .
           stuff (buttons/labels and so on).
           .
           .
  &lt;/Pane&gt;
  </code></pre>
  
  <p>I would appreciate any help! Thanks in advance.</p>
  
  <h2>Update 1</h2>
  
  <p>Also took in consideration this reference: <a href="https://stackoverflow.com/questions/10751271/accessing-fxml-controller-class">Accessing FXML controller class</a></p>