title: JavaFX Event Handler No longer working
body: <p>In My code I created an event handler that originally worked; however after adding more code it stopped working so I restored to before my changes and it still won't work. Is there something that I have done wrong? Also, I am using eclipse if that is helpful in determining a cause.</p>
  
  <p>Main.java:
      package application;</p>
  
  <pre><code>import java.util.ArrayList;
  
  import javafx.application.Application;
  import javafx.event.EventHandler;
  import javafx.fxml.FXMLLoader;
  import javafx.stage.Stage;
  import javafx.scene.Node;
  import javafx.scene.Parent;
  import javafx.scene.Scene;
  import javafx.scene.input.InputEvent;
  import javafx.scene.input.MouseEvent;
  
  
  public class Main extends Application {
      public Parent root;
      public ChessUtil chess = new ChessUtil();
      @Override
      public void start(Stage primaryStage) {
          try {
              root = FXMLLoader.load(getClass().getResource("/Chess.fxml"));
              Node peice;
              for(int x = 0; x &lt; 16 ;x++)
              {
                  peice = root.lookup("#" + chess.whiteID[x]);
                  peice.addEventHandler(MouseEvent.MOUSE_CLICKED, peiceClick);
                  peice = root.lookup("#" + chess.blackID[x]);
                  peice.addEventHandler(MouseEvent.MOUSE_CLICKED, peiceClick);
              }
              disablePeicesToggle(chess.blackID, true);
              Scene scene = new Scene(root,740,740);
              scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
              primaryStage.setScene(scene);
              primaryStage.show();
          } catch(Exception e) {
              e.printStackTrace();
          }
      }
      EventHandler peiceClick = new EventHandler&lt;InputEvent&gt;() {
          public void handle(InputEvent event) {
              String id = ((Node) event.getSource()).getId();
              ArrayList&lt;String&gt; moves = chess.findPeiceMoves(id);
              System.out.println(moves.size());
              if(moves.size() &gt; 0)
              {
                  System.out.println(moves);
              }
              System.out.println("Handling event " + event.getEventType()); 
              event.consume();
          }
       };
      public void disablePeicesToggle(String[] idSet, boolean disable)
      {
          Node peice;
          for(int x = 0; x &lt; 16 ;x++)
          {
              peice = root.lookup("#" + idSet[x]);
              peice.setDisable(disable);
          }
  
      }
      public static void main(String[] args) {
          launch(args);
      }
  }
  </code></pre>
  
  <p>Chess.fxml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import java.lang.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  &lt;?import javafx.scene.layout.AnchorPane?&gt;
  
  &lt;AnchorPane prefHeight="740.0" prefWidth="740.0" stylesheets="@application/application.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"&gt;
     &lt;children&gt;
        &lt;AnchorPane id="chessboard" layoutX="10.0" layoutY="10.0" prefHeight="720.0" prefWidth="720.0" stylesheets="@application/application.css" /&gt;
        &lt;AnchorPane id="board-spaces" layoutX="50.0" layoutY="50.0" prefHeight="640.0" prefWidth="640.0"&gt;
           &lt;children&gt;
              &lt;Region id="b7" prefHeight="80.0" prefWidth="80.0" styleClass="bRook" /&gt;
              &lt;Region id="b3" layoutX="160.0" prefHeight="80.0" prefWidth="80.0" styleClass="bBishop" /&gt;
              &lt;Region id="b5" layoutX="80.0" prefHeight="80.0" prefWidth="80.0" styleClass="bKnight" /&gt;
              &lt;Region id="b2" layoutX="240.0" prefHeight="80.0" prefWidth="80.0" styleClass="bQueen" /&gt;
              &lt;Region id="b1" layoutX="320.0" prefHeight="80.0" prefWidth="80.0" styleClass="bKing" /&gt;
              &lt;Region id="b4" layoutX="400.0" prefHeight="80.0" prefWidth="80.0" styleClass="bBishop" /&gt;
              &lt;Region id="b6" layoutX="480.0" prefHeight="80.0" prefWidth="80.0" styleClass="bKnight" /&gt;
              &lt;Region id="b8" layoutX="560.0" prefHeight="80.0" prefWidth="80.0" styleClass="bRook" /&gt;
              &lt;Region id="b12" layoutX="240.0" layoutY="80.0" prefHeight="80.0" prefWidth="80.0" styleClass="bPawn" /&gt;
              &lt;Region id="b10" layoutX="80.0" layoutY="80.0" prefHeight="80.0" prefWidth="80.0" styleClass="bPawn" /&gt;
              &lt;Region id="b13" layoutX="320.0" layoutY="80.0" prefHeight="80.0" prefWidth="80.0" styleClass="bPawn" /&gt;
              &lt;Region id="b16" layoutX="560.0" layoutY="80.0" prefHeight="80.0" prefWidth="80.0" styleClass="bPawn" /&gt;
              &lt;Region id="b9" layoutY="80.0" prefHeight="80.0" prefWidth="80.0" styleClass="bPawn" /&gt;
              &lt;Region id="b15" layoutX="480.0" layoutY="80.0" prefHeight="80.0" prefWidth="80.0" styleClass="bPawn" /&gt;
              &lt;Region id="b11" layoutX="160.0" layoutY="80.0" prefHeight="80.0" prefWidth="80.0" styleClass="bPawn" /&gt;
              &lt;Region id="b14" layoutX="400.0" layoutY="80.0" prefHeight="80.0" prefWidth="80.0" styleClass="bPawn" /&gt;
              &lt;Region id="w3" layoutX="160.0" layoutY="560.0" prefHeight="80.0" prefWidth="80.0" styleClass="wBishop" /&gt;
              &lt;Region id="w12" layoutX="240.0" layoutY="480.0" prefHeight="80.0" prefWidth="80.0" styleClass="wPawn" /&gt;
              &lt;Region id="w10" layoutX="80.0" layoutY="480.0" prefHeight="80.0" prefWidth="80.0" styleClass="wPawn" /&gt;
              &lt;Region id="w5" layoutX="80.0" layoutY="560.0" prefHeight="80.0" prefWidth="80.0" styleClass="wKnight" /&gt;
              &lt;Region id="w7" layoutY="560.0" prefHeight="80.0" prefWidth="80.0" styleClass="wRook" /&gt;
              &lt;Region id="w14" layoutX="400.0" layoutY="480.0" prefHeight="80.0" prefWidth="80.0" styleClass="wPawn" /&gt;
              &lt;Region id="w1" layoutX="320.0" layoutY="560.0" prefHeight="80.0" prefWidth="80.0" styleClass="wKing" /&gt;
              &lt;Region id="w2" layoutX="240.0" layoutY="560.0" prefHeight="80.0" prefWidth="80.0" styleClass="wQueen" /&gt;
              &lt;Region id="w6" layoutX="480.0" layoutY="560.0" prefHeight="80.0" prefWidth="80.0" styleClass="wKnight" /&gt;
              &lt;Region id="w13" layoutX="320.0" layoutY="480.0" prefHeight="80.0" prefWidth="80.0" styleClass="wPawn" /&gt;
              &lt;Region id="w16" layoutX="560.0" layoutY="480.0" prefHeight="80.0" prefWidth="80.0" styleClass="wPawn" /&gt;
              &lt;Region id="w9" layoutY="480.0" prefHeight="80.0" prefWidth="80.0" styleClass="wPawn" /&gt;
              &lt;Region id="w15" layoutX="480.0" layoutY="480.0" prefHeight="80.0" prefWidth="80.0" styleClass="wPawn" /&gt;
              &lt;Region id="w11" layoutX="160.0" layoutY="480.0" prefHeight="80.0" prefWidth="80.0" styleClass="wPawn" /&gt;
              &lt;Region id="w8" layoutX="560.0" layoutY="560.0" prefHeight="80.0" prefWidth="80.0" styleClass="wRook" /&gt;
              &lt;Region id="w4" layoutX="400.0" layoutY="560.0" prefHeight="80.0" prefWidth="80.0" styleClass="wBishop" /&gt;
           &lt;/children&gt;&lt;/AnchorPane&gt;
           &lt;AnchorPane id="board-overlay" layoutX="60.0" layoutY="60.0" prefHeight="640.0" prefWidth="640.0" /&gt;
     &lt;/children&gt;
  &lt;/AnchorPane&gt;
  </code></pre>
  
  <p>Update: I have put my code in a GitHub repo.
   Full Source code is at github.com/stitch366/chess/tree/master/chess.</p>