title: javafx fxml LoadException
body: <p>I am quite new at JavaFx. I am trying to build a simple calculator by following a tutorial . I followed the tutorial step by step . When I run the project , it shows javafx fxml LoadException. I watched some solution relating to this but still I can not fix it. Please help me to fix this error.(Sorry for a long post) </p>
  
  <p>my program files are below</p>
  
  <p><strong>MainController.java</strong></p>
  
  <pre><code>package application;
  import javafx.event.ActionEvent;
  import javafx.fxml.FXML;
  import javafx.scene.control.Button;
  import javafx.scene.control.Label;
  
  public class MainController {
  
  @FXML
  private Label result; // label variable shows output above the buttons, check this
  private long number1 = 0;
  private String operator = "";
  private boolean start = true;
  private Model model = new Model();
  
  @FXML
  public void processNumbers(ActionEvent event) {
      if (start) {
          result.setText(""); // set the label(output) screen as blank first
          start = false;
      }
      String value = ((Button) event.getSource()).getText(); // take number 1-9 and convert it into String, import the
                                                              // button class otherwise will shows error
      result.setText(result.getText() + value);
  }
  
  @FXML
  public void processOperators(ActionEvent event) {
      String value = ((Button) event.getSource()).getText();`enter code here`
  
      if (!value.equals("=")) {
          if (!operator.isEmpty()) {
              return;
          }
          operator = value;
          number1 = Long.parseLong(result.getText());
          result.setText("");
      } else {
          if (operator.isEmpty())
              return;
          long number2 = Long.parseLong(result.getText());
          float output = model.calculate(number2, number2, operator); 
  
          result.setText(String.valueOf(output));
          start = true;
          }
        }
  
   }
  </code></pre>
  
  <p><strong>Model.java</strong></p>
  
  <pre><code> package application;
  
  public class Model { //for some action event 
  
      public float calculate(long number1,long number2,String operator) {
  
      switch(operator) {
          case "+":
              return number1+number2;
          case "-":
              return number1-number2;
          case "*":
              return number1*number2;
          case "/":
              if(number2==0) return 0;
              return number1+number2;
          default:
              return 0;
  
          }//switch case
  
  
      }
  
  
  }
  </code></pre>
  
  <p><strong>Main.java</strong></p>
  
  <pre><code>package application;
  
  import javafx.application.Application;
  import javafx.fxml.FXMLLoader;
  import javafx.stage.Stage;
  import javafx.scene.Parent;
  import javafx.scene.Scene;
  import javafx.scene.layout.BorderPane;
  import javafx.scene.control.*;
  
  public class Main extends Application {
      @Override
      public void start(Stage primaryStage) {
          try {
              Parent root = (Parent) FXMLLoader.load(getClass().getResource("/application/CalculatorFxmlFile.fxml"));
              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);
      }
  }
  </code></pre>
  
  <p><strong>CalculatorFxmlFile</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import javafx.scene.control.Button?&gt;
  &lt;?import javafx.scene.control.Label?&gt;
  &lt;?import javafx.scene.layout.HBox?&gt;
  &lt;?import javafx.scene.layout.StackPane?&gt;
  &lt;?import javafx.scene.layout.VBox?&gt;
  &lt;?import javafx.scene.text.Font?&gt;
  
  &lt;VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="300.0" prefWidth="300.0" spacing="10.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.MainController"&gt;
     &lt;children&gt;
        &lt;StackPane prefHeight="50.0" prefWidth="200.0"&gt;
           &lt;children&gt;
              &lt;Label fx:id="result" prefHeight="17.0" prefWidth="327.0" text="Label"&gt;
                 &lt;font&gt;
                    &lt;Font name="System Bold" size="18.0" /&gt;
                 &lt;/font&gt;
              &lt;/Label&gt;
           &lt;/children&gt;&lt;/StackPane&gt;
        &lt;HBox alignment="CENTER" prefHeight="50.0" prefWidth="300.0" spacing="10.0"&gt;
           &lt;children&gt;
              &lt;Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="7"&gt;
                 &lt;font&gt;
                    &lt;Font size="18.0" /&gt;
                 &lt;/font&gt;
              &lt;/Button&gt;
              &lt;Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="8"&gt;
                 &lt;font&gt;
                    &lt;Font size="18.0" /&gt;
                 &lt;/font&gt;
              &lt;/Button&gt;
              &lt;Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="9"&gt;
                 &lt;font&gt;
                    &lt;Font size="18.0" /&gt;
                 &lt;/font&gt;
              &lt;/Button&gt;
              &lt;Button fx:id="result" mnemonicParsing="false" onAction="#processOperators" prefWidth="50.0" text="/"&gt;
                 &lt;font&gt;
                    &lt;Font size="18.0" /&gt;
                 &lt;/font&gt;
              &lt;/Button&gt;
           &lt;/children&gt;
        &lt;/HBox&gt;
        &lt;HBox alignment="CENTER" prefHeight="50.0" prefWidth="300.0" spacing="10.0"&gt;
           &lt;children&gt;
              &lt;Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="4"&gt;
                 &lt;font&gt;
                    &lt;Font size="18.0" /&gt;
                 &lt;/font&gt;
              &lt;/Button&gt;
              &lt;Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="5"&gt;
                 &lt;font&gt;
                    &lt;Font size="18.0" /&gt;
                 &lt;/font&gt;
              &lt;/Button&gt;
              &lt;Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="6"&gt;
                 &lt;font&gt;
                    &lt;Font size="18.0" /&gt;
                 &lt;/font&gt;
              &lt;/Button&gt;
              &lt;Button mnemonicParsing="false" onAction="#processOperators" prefWidth="50.0" text="*"&gt;
                 &lt;font&gt;
                    &lt;Font size="18.0" /&gt;
                 &lt;/font&gt;
              &lt;/Button&gt;
           &lt;/children&gt;
        &lt;/HBox&gt;
        &lt;HBox alignment="CENTER" prefHeight="50.0" prefWidth="300.0" spacing="10.0"&gt;
           &lt;children&gt;
              &lt;Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="1"&gt;
                 &lt;font&gt;
                    &lt;Font size="18.0" /&gt;
                 &lt;/font&gt;
              &lt;/Button&gt;
              &lt;Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="2"&gt;
                 &lt;font&gt;
                    &lt;Font size="18.0" /&gt;
                 &lt;/font&gt;
              &lt;/Button&gt;
              &lt;Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="50.0" text="3"&gt;
                 &lt;font&gt;
                    &lt;Font size="18.0" /&gt;
                 &lt;/font&gt;
              &lt;/Button&gt;
              &lt;Button mnemonicParsing="false" onAction="#processOperators" prefWidth="50.0" text="-"&gt;
                 &lt;font&gt;
                    &lt;Font size="18.0" /&gt;
                 &lt;/font&gt;
              &lt;/Button&gt;
           &lt;/children&gt;
        &lt;/HBox&gt;
        &lt;HBox alignment="CENTER" prefHeight="50.0" prefWidth="300.0" spacing="10.0"&gt;
           &lt;children&gt;
              &lt;Button mnemonicParsing="false" onAction="#processNumbers" prefWidth="110.0" text="0"&gt;
                 &lt;font&gt;
                    &lt;Font size="18.0" /&gt;
                 &lt;/font&gt;
              &lt;/Button&gt;
              &lt;Button mnemonicParsing="false" onAction="#processOperators" prefWidth="50.0" text="="&gt;
                 &lt;font&gt;
                    &lt;Font size="18.0" /&gt;
                 &lt;/font&gt;
              &lt;/Button&gt;
              &lt;Button mnemonicParsing="false" onAction="#processOperators" prefWidth="50.0" text="+"&gt;
                 &lt;font&gt;
                    &lt;Font size="18.0" /&gt;
                 &lt;/font&gt;
              &lt;/Button&gt;
           &lt;/children&gt;
        &lt;/HBox&gt;
     &lt;/children&gt;
  &lt;/VBox&gt;
  </code></pre>
  
  <p><strong>Exceptions generated</strong></p>
  
  <pre><code>javafx.fxml.LoadException: 
  /C:/AllPrograms/Java/eclipse1/CalculatorJavaFx/bin/application/CalculatorFxmlFile.fxml:37
  
      at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
      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.Main.start(Main.java:15)
      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(Unknown Source)
  Caused by: java.lang.IllegalArgumentException: Can not set javafx.scene.control.Label field application.MainController.result to javafx.scene.control.Button
      at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
      at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
      at sun.reflect.UnsafeObjectFieldAccessorImpl.set(Unknown Source)
      at java.lang.reflect.Field.set(Unknown Source)
      at javafx.fxml.FXMLLoader.injectFields(FXMLLoader.java:1163)
      at javafx.fxml.FXMLLoader.access$1600(FXMLLoader.java:103)
      at javafx.fxml.FXMLLoader$ValueElement.processValue(FXMLLoader.java:857)
      at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:751)
      at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
      ... 17 more
  </code></pre>