title: JavaFx, Problems with @FXML
body: <p>I'm new in java, so I have to ask you for help :P.
  I'm creating very simple program, but I stucked on verifying password and login textField. I'm wondering what is wrong with that code, can you help me?</p>
  
  <p>Controller</p>
  
  <pre><code>package sample;
  
  import javafx.event.ActionEvent;
  import javafx.fxml.FXML;
  import javafx.fxml.Initializable;
  import javafx.scene.control.PasswordField;
  
  import java.awt.*;
  
  public class Controller {
      @FXML
      public TextField login,password;
      public void LoginButtonClicked(ActionEvent event)
      {
      if(login.getText().equals("yes")&amp;&amp;password.getText().equals("yes"))
          {
              System.out.print("Congratulations");
          }
      else
          {
              System.out.print("no");
          }
  
      }
  
  
  }
  </code></pre>
  
  <p>FXML</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import javafx.scene.text.*?&gt;
  &lt;?import javafx.geometry.*?&gt;
  &lt;?import javafx.scene.control.*?&gt;
  &lt;?import java.lang.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  &lt;?import javafx.geometry.Insets?&gt;
  &lt;?import javafx.scene.layout.GridPane?&gt;
  &lt;?import javafx.scene.control.Button?&gt;
  &lt;?import javafx.scene.control.Label?&gt;
  
  &lt;BorderPane 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="sample.Controller"&gt;
     &lt;top&gt;
        &lt;VBox BorderPane.alignment="CENTER"&gt;
           &lt;children&gt;
              &lt;MenuBar&gt;
                &lt;menus&gt;
                  &lt;Menu mnemonicParsing="false" text="Profile"&gt;
                    &lt;items&gt;
                      &lt;MenuItem mnemonicParsing="false" text="Your Profile" /&gt;
                          &lt;MenuItem mnemonicParsing="false" text="Log out" /&gt;
                          &lt;MenuItem mnemonicParsing="false" text="Close" /&gt;
                    &lt;/items&gt;
                  &lt;/Menu&gt;
                  &lt;Menu mnemonicParsing="false" text="Help"&gt;
                    &lt;items&gt;
                      &lt;MenuItem mnemonicParsing="false" text="About program" /&gt;
                          &lt;MenuItem mnemonicParsing="false" text="Author" /&gt;
                    &lt;/items&gt;
                  &lt;/Menu&gt;
                &lt;/menus&gt;
              &lt;/MenuBar&gt;
              &lt;HBox spacing="8.0"&gt;
                 &lt;children&gt;
                    &lt;TextField fx:id="login" promptText="User" /&gt;               // ERROR
                    &lt;TextField fx:id="password" layoutX="10.0" layoutY="10.0" promptText="Password" /&gt;                                      //ERROR
                    &lt;Region HBox.hgrow="ALWAYS" /&gt;
                    &lt;Button mnemonicParsing="false" onAction="#LoginButtonClicked" text="Log In" /&gt;
                    &lt;Button layoutX="329.0" layoutY="15.0" mnemonicParsing="false" text="Clear" /&gt;
                 &lt;/children&gt;
                 &lt;padding&gt;
                    &lt;Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /&gt;
                 &lt;/padding&gt;
              &lt;/HBox&gt;
           &lt;/children&gt;
        &lt;/VBox&gt;
     &lt;/top&gt;
     &lt;center&gt;
        &lt;Label alignment="CENTER" prefHeight="130.0" prefWidth="469.0" text="Log in, in order to use this program" BorderPane.alignment="CENTER"&gt;
           &lt;font&gt;
              &lt;Font size="25.0" /&gt;
           &lt;/font&gt;
        &lt;/Label&gt;
     &lt;/center&gt;
  &lt;/BorderPane&gt;
  </code></pre>
  
  <p>And the error code</p>
  
  <pre><code>Exception in Application start method
  Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
      at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:875)
      at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(LauncherImpl.java:157)
      at com.sun.javafx.application.LauncherImpl$$Lambda$1/868693306.run(Unknown Source)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: javafx.fxml.LoadException: 
  /C:/Users/Michael/IdeaProjects/Endomondo/out/production/Endomondo/sample/sample.fxml:36
  
      at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2595)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2573)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2435)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3208)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3169)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3142)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3118)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3098)
      at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3091)
      at sample.Main.start(Main.java:13)
      at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(LauncherImpl.java:821)
      at com.sun.javafx.application.LauncherImpl$$Lambda$50/1482523563.run(Unknown Source)
      at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(PlatformImpl.java:323)
      at com.sun.javafx.application.PlatformImpl$$Lambda$46/1674404664.run(Unknown Source)
      at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
      at com.sun.javafx.application.PlatformImpl$$Lambda$48/992465164.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
      at com.sun.javafx.application.PlatformImpl$$Lambda$47/668291877.run(Unknown Source)
      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$141(WinApplication.java:102)
      at com.sun.glass.ui.win.WinApplication$$Lambda$38/1584193862.run(Unknown Source)
      ... 1 more
  Caused by: java.lang.IllegalArgumentException: Can not set java.awt.TextField field sample.Controller.login to javafx.scene.control.TextField
      at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
      at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
      at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
      at java.lang.reflect.Field.set(Field.java:758)
      at javafx.fxml.FXMLLoader.injectFields(FXMLLoader.java:1155)
      at javafx.fxml.FXMLLoader.access$1600(FXMLLoader.java:104)
      at javafx.fxml.FXMLLoader$ValueElement.processValue(FXMLLoader.java:853)
      at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:747)
      at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2701)
      at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2521)
      ... 22 more
  </code></pre>