title: ClassCastException in JavaFX
body: <p>My code gets the following error. </p>
  
  <pre><code>Exception in thread "JavaFX Application Thread" java.lang.ClassCastException: javafx.scene.Group cannot be cast to javafx.scene.control.TreeCell
  </code></pre>
  
  <p><strong>Source code</strong></p>
  
  <pre><code>private TreeItem getClickedTreeItem(EventTarget eventTarget){
      TreeItem clickedTreeItem = null;
  
      if(eventTarget instanceof TreeCellSkin){
          clickedTreeItem = (TreeItem) ((TreeCell) ((TreeCellSkin)eventTarget).getParent()).getTreeItem();
      }else if(eventTarget instanceof LabeledText){
          clickedTreeItem = (TreeItem) ((TreeCell) ((LabeledText)eventTarget).getParent().getParent()).getTreeItem();
      }else if(eventTarget instanceof ImageView){
          clickedTreeItem = (TreeItem) ((TreeCell) ((ImageView)eventTarget).getParent().getParent()).getTreeItem();
      }
  
      return clickedTreeItem;
  }
  </code></pre>
  
  <p>The console says this line: </p>
  
  <pre><code>clickedTreeItem = (TreeItem) ((TreeCell) ((ImageView)eventTarget).getParent().getParent()).getTreeItem();
  </code></pre>
  
  <p>This is legacy code that worked with Java 6, but gives the above exception using Java8? </p>
  
  <p>What could be causing the <code>ClassCastException</code> now, and how to fix it for Java8?</p>