title: JavaFX TableCell ClassCastException
body: <p>I have a TableView with editable Cells.</p>
  
  <p>One Cell includes an editable Cell with a combobox. If I want to change the current value I get a ClassCast Exception. But I couldn't find any variable which is as String. </p>
  
  <p>Which method change the instance too String?</p>
  
  <p>Thanks!!</p>
  
  <p>controller:</p>
  
  <pre><code>cols.get(1).setCellValueFactory(new PropertyValueFactory&lt;LieferscheinArtikel, Produkt&gt;("produkt"));
      Callback&lt;TableColumn, TableCell&gt; cellFactoryProdukt =
                new Callback&lt;TableColumn, TableCell&gt;() {
                    public TableCell call(TableColumn p) {
                        return new LieferscheinArtikelEditingProdukt();
                    }
                };
      cols.get(1).setCellFactory(cellFactoryProdukt);
      cols.get(1).setOnEditCommit(new EventHandler&lt;TableColumn.CellEditEvent&lt;LieferscheinArtikel, Produkt&gt;&gt;() {
  
          @Override
          public void handle(CellEditEvent&lt;LieferscheinArtikel, Produkt&gt; event) {
              // TODO Auto-generated method stub
  
          }
      });
  </code></pre>
  
  <p>TableCell class:</p>
  
  <pre><code>public class LieferscheinArtikelEditingProdukt extends
      TableCell&lt;LieferscheinArtikel, Produkt&gt; {
  
  private ComboBox&lt;Produkt&gt; combobox;
  private AutoCompleteComboBoxListener&lt;Produkt&gt; auto;
  
  public LieferscheinArtikelEditingProdukt() {
      combobox = new ComboBox&lt;Produkt&gt;();
      auto = new AutoCompleteComboBoxListener&lt;Produkt&gt;(combobox);
      combobox.setItems(ProduktDataObserv.getInstance("normal").getProduktData());
      combobox.valueProperty().addListener(new ChangeListener&lt;Produkt&gt;() {
  
          @Override
          public void changed(ObservableValue&lt;? extends Produkt&gt; observable,
                  Produkt oldValue, Produkt newValue) {
              System.out.println("change: "+oldValue+" "+newValue);
              setItem(newValue);
              System.out.println((getItem() instanceof Produkt) +" "+getItem());
          }
      });
  
  }
  
  @Override
  public void startEdit() {
      super.startEdit();
  
      if(getItem() != null){
          System.out.println((getItem() instanceof Produkt) +" "+getItem());
          combobox.getSelectionModel().select(getItem());
      }
      //setGraphic(textField);
      setGraphic(combobox);
      setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
      //textField.selectAll();
  }
  
  @Override
  public void cancelEdit() {
      //super.cancelEdit();
      //System.out.println("exit: "+combobox.getSelectionModel().getSelectedItem());
      //setText(getItem());
      System.out.println("can: "+getItem() instanceof String);
      //setItem(combobox.getSelectionModel().getSelectedItem());
      //setText(combobox.getSelectionModel().getSelectedItem().toString());
      //setText(getItem().toString());
      setGraphic(null);
      setContentDisplay(ContentDisplay.TEXT_ONLY);
  }
  
  @Override
  public void updateItem(Produkt item, boolean empty) {
      if(getItem() != null){
      System.out.println("upd: "+this.getItem()!=null?getItem().toString():null);
      //super.updateItem(item, empty);
      System.out.println((getItem() instanceof Produkt) +" "+getItem());
      }
      if (empty) {
          //setText(null);
          setGraphic(null);
      } else {
          if (isEditing()) {
              if (combobox != null) {
                  combobox.getSelectionModel().select(item);
              }
              setGraphic(combobox);
              setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
          } else {
              setItem(item);
              //setText(getItem() != null ? getItem().toString() : null);
              setContentDisplay(ContentDisplay.TEXT_ONLY);
          }
      }
      setItem(item);
      //setText(getItem() != null ? getItem().toString() : null);
  }
  </code></pre>
  
  <p>error message:</p>
  
  <pre><code>Exception in thread "JavaFX Application Thread" java.lang.ClassCastException: java.lang.String cannot be cast to Produkte.Produkt
  at LieferscheinArtikelBearbeiten.LieferscheinArtikelEditingProdukt$1.changed(LieferscheinArtikelEditingProdukt.java:1)
  at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:347)
  at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80)
  at javafx.beans.property.ObjectPropertyBase.fireValueChangedEvent(ObjectPropertyBase.java:105)
  at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
  at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:145)
  at javafx.scene.control.ComboBoxBase.setValue(ComboBoxBase.java:167)
  at com.sun.javafx.scene.control.skin.ComboBoxListViewSkin.setTextFromTextFieldIntoComboBoxValue(ComboBoxListViewSkin.java:512)
  at com.sun.javafx.scene.control.skin.ComboBoxListViewSkin.access$200(ComboBoxListViewSkin.java:57)
  at com.sun.javafx.scene.control.skin.ComboBoxListViewSkin$6.changed(ComboBoxListViewSkin.java:416)
  at com.sun.javafx.scene.control.skin.ComboBoxListViewSkin$6.changed(ComboBoxListViewSkin.java:406)
  at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:347)
  at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80)
  at javafx.beans.property.ReadOnlyBooleanPropertyBase.fireValueChangedEvent(ReadOnlyBooleanPropertyBase.java:72)
  at javafx.scene.Node$FocusedProperty.notifyListeners(Node.java:7486)
  at javafx.scene.Node.setFocused(Node.java:7537)
  at com.sun.javafx.scene.control.skin.ComboBoxListViewSkin$FakeFocusTextField.setFakeFocus(ComboBoxListViewSkin.java:697)
  at com.sun.javafx.scene.control.skin.ComboBoxListViewSkin$2.changed(ComboBoxListViewSkin.java:145)
  at com.sun.javafx.scene.control.skin.ComboBoxListViewSkin$2.changed(ComboBoxListViewSkin.java:141)
  at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:347)
  at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80)
  at javafx.beans.property.ReadOnlyBooleanPropertyBase.fireValueChangedEvent(ReadOnlyBooleanPropertyBase.java:72)
  at javafx.scene.Node$FocusedProperty.notifyListeners(Node.java:7486)
  at javafx.scene.Scene$15.invalidated(Scene.java:2073)
  at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:111)
  at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:145)
  at javafx.scene.Scene$KeyHandler.setFocusOwner(Scene.java:3910)
  at javafx.scene.Scene$KeyHandler.requestFocus(Scene.java:3956)
  at javafx.scene.Scene$KeyHandler.access$2200(Scene.java:3896)
  at javafx.scene.Scene.requestFocus(Scene.java:2040)
  at javafx.scene.Node.requestFocus(Node.java:7647)
  at com.sun.javafx.scene.control.behavior.TableViewBehaviorBase.mousePressed(TableViewBehaviorBase.java:430)
  at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:95)
  at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
  at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
  at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
  at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
  at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
  at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
  at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
  at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
  at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
  at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
  at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
  at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
  at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
  at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
  at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
  at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
  at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
  at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
  at javafx.event.Event.fireEvent(Event.java:204)
  at javafx.scene.Scene$MouseHandler.process(Scene.java:3746)
  at javafx.scene.Scene$MouseHandler.access$1800(Scene.java:3471)
  at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1695)
  at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2486)
  at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:314)
  at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:243)
  at java.security.AccessController.doPrivileged(Native Method)
  at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:345)
  at com.sun.glass.ui.View.handleMouseEvent(View.java:526)
  at com.sun.glass.ui.View.notifyMouse(View.java:898)
  </code></pre>
  
  <p>LieferscheinArtikel:</p>
  
  <p>public class LieferscheinArtikel {</p>
  
  <pre><code>private IntegerProperty position;
  private FloatProperty menge;
  private ObjectProperty&lt;Produkt&gt; produkt = new SimpleObjectProperty&lt;Produkt&gt;(this,"produkt");
  private FloatProperty preis;
  private StringProperty notiz;
  private FloatProperty retour;
  
  public LieferscheinArtikel() {
      produkt.set(ProduktDataObserv.getInstance("normal").getProdukt(1));
      preis = new SimpleFloatProperty(produkt.get().getPreis());
      retour = new SimpleFloatProperty(0);
  }
  
  public LieferscheinArtikel(int produktnr) {
      produkt.set(ProduktDataObserv.getInstance("normal").getProdukt(produktnr));
      preis = new SimpleFloatProperty(produkt.get().getPreis());
      retour = new SimpleFloatProperty(0);
  }
  
  public LieferscheinArtikel(int position, float menge, float retour,
          int produktnr, String produktart, float preis, String notiz) {
      this.position = new SimpleIntegerProperty(position);
      this.menge = new SimpleFloatProperty(menge);
      produkt.set(ProduktDataObserv.getInstance(
              produktart.startsWith("KNr") ? produktart : "normal")
              .getProdukt(produktnr));
      this.preis = new SimpleFloatProperty(preis);
      this.notiz = new SimpleStringProperty(notiz);
      this.retour = new SimpleFloatProperty(retour);
  }
  
  public float getMenge() {
      return menge.get();
  }
  
  public void setMenge(float menge) {
      this.menge.set(menge);
  }
  
  public float getPreis() {
      return preis.get();
  }
  
  public void setPreis(float preis) {
      this.preis.set(preis);
      ;
  }
  
  public Produkt getProdukt() {
      return produkt.get();
  }
  
  public void setProdukt(Produkt produkt) {
      System.out.println("setin");
      this.produkt.set(produkt);
  }
  
  public String getNotiz() {
      return notiz == null ? "" : notiz.get();
  }
  
  public void setNotiz(String notiz) {
      this.notiz.set(notiz);
  }
  
  public int getPosition() {
      return position == null ? 1 : position.get();
  }
  
  public void setPosition(int position) {
      this.position.set(position);
  }
  
  public float getRetour() {
      return retour.get();
  }
  
  public void setRetour(float retour) {
      this.retour.set(retour);
  }
  
  public String getPreisanz() {
      return String.format("%.2f \u20ac", preis.get());
  }
  
  public ObjectProperty&lt;Produkt&gt; produktProperty(){
      return produkt;
  }
  
  public String getRetouranz() {
      System.out.println(retour + " "+produkt.get().isIsRetourMoeglich());
      if (!produkt.get().isIsRetourMoeglich())
          return "XXXX";
      else
      if (retour == null)
          return "";
      else
          return String.format("%.2f", retour.get());
  }
  
  @Override
  public int hashCode() {
      int hash = 7;
      return hash;
  }
  
  @Override
  public boolean equals(Object obj) {
      if (obj == null) {
          return false;
      }
      if (getClass() != obj.getClass()) {
          return false;
      }
      final LieferscheinArtikel other = (LieferscheinArtikel) obj;
      if (this.menge != null &amp;&amp; other != null)
          try {
              if (Float.floatToIntBits(this.menge.get()) != Float
                      .floatToIntBits(other.menge.get())) {
                  return false;
              }
          } catch (NullPointerException ex) {
  
          }
      if (this.produkt != null)
          if (!Objects.equals(this.produkt, other.produkt)) {
              return false;
          }
      if (this.preis != null)
          if (Float.floatToIntBits(this.preis.get()) != Float
                  .floatToIntBits(other.preis.get())) {
              return false;
          }
      if (this.notiz != null)
          if (!Objects.equals(this.notiz, other.notiz)) {
              return false;
          }
      return true;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Produkt:</p>
  
  <p>public class Produkt {</p>
  
  <pre><code>private IntegerProperty produktid;
  private StringProperty bezeichnung;
  private StringProperty mengeneinheit;
  private FloatProperty preis;
  private IntegerProperty mwst;
  private StringProperty art_der_ware;
  private BooleanProperty isRetourMoeglich;
  
  public Produkt(int produktid, String bezeichnung, String mengeneinheit, float preis, int mwst, String art_der_ware, boolean isRetourMoeglich) {
      this.produktid = new SimpleIntegerProperty(produktid);
      this.bezeichnung = new SimpleStringProperty(bezeichnung);
      this.mengeneinheit = new SimpleStringProperty(mengeneinheit);
      this.preis = new SimpleFloatProperty(preis);
      this.mwst = new SimpleIntegerProperty(mwst);
      this.art_der_ware = new  SimpleStringProperty(art_der_ware);
      this.isRetourMoeglich = new SimpleBooleanProperty(isRetourMoeglich);
  }
  
  public Produkt(int produktid, String bezeichnung, String mengeneinheit, float preis, int mwst, String art_der_ware) {
      this.produktid = new SimpleIntegerProperty(produktid);
      this.bezeichnung = new SimpleStringProperty(bezeichnung);
      this.mengeneinheit = new SimpleStringProperty(mengeneinheit);
      this.preis = new SimpleFloatProperty(preis);
      this.mwst = new SimpleIntegerProperty(mwst);
      this.art_der_ware = new  SimpleStringProperty(art_der_ware);
      this.isRetourMoeglich =new SimpleBooleanProperty(false);
  
  }
  
  public Produkt(){
      this.produktid = new SimpleIntegerProperty(0);
      this.bezeichnung =new SimpleStringProperty("");
      this.mengeneinheit = new SimpleStringProperty("");
      this.preis = new SimpleFloatProperty(0.0f);
      this.mwst = new SimpleIntegerProperty(0);
      this.art_der_ware = new SimpleStringProperty("");
      this.isRetourMoeglich =new SimpleBooleanProperty(false);
  }
  
  public Produkt(int produktNr){
      this.produktid = new SimpleIntegerProperty(produktNr);
  }
  
  
  public int getProduktid() {
      return produktid.get();
  }
  
  public void setProduktid(int produktid) {
      this.produktid.set(produktid);
  }
  
  public String getBezeichnung() {
      return bezeichnung.get();
  }
  
  public void setBezeichnung(String bezeichnung) {
      this.bezeichnung.set(bezeichnung);
  }
  
  public String getMengeneinheit() {
      return mengeneinheit.get();
  }
  
  public void setMengeneinheit(String mengeneinheit) {
      this.mengeneinheit.set(mengeneinheit);
  }
  
  public float getPreis() {
      return preis.get();
  }
  
  public void setPreis(float preis) {
      this.preis.set(preis);
  }
  
  public int getMwst() {
      return mwst.get();
  }
  
  public void setMwst(int mwst) {
      this.mwst.set(mwst);
  }
  
  public String getArt_der_ware() {
      return art_der_ware.get();
  }
  
  public void setArt_der_ware(String art_der_ware) {
      this.art_der_ware.set(art_der_ware);
  }
  
  public boolean isSomethingEmpty() {
      return (!art_der_ware.get().isEmpty()
              &amp;&amp; !bezeichnung.get().isEmpty()
              &amp;&amp; !mengeneinheit.get().isEmpty()
              &amp;&amp; (mwst.get() != 0)
              &amp;&amp; (preis.get() != 0)
              &amp;&amp; produktid.get() != 0);
  }
  
  public boolean isIsRetourMoeglich() {
      return isRetourMoeglich.get();
  }
  
  public void setIsRetourMoeglich(boolean isRetourMoeglich) {
      this.isRetourMoeglich.set(isRetourMoeglich);
  }
  
  
  
  @Override
  public String toString() {
      return bezeichnung.get();
  }
  
  @Override
  public boolean equals(Object obj) {
      if (obj == null) {
          return false;
      }
      if(obj instanceof Produkt){
      final Produkt other = (Produkt) obj;
      /*if (this.produktid == other.produktid
              &amp;&amp; this.art_der_ware.equals(other.art_der_ware)
              &amp;&amp; this.bezeichnung.equals(other.bezeichnung)
              &amp;&amp; this.mengeneinheit.equals(other.mengeneinheit)
              &amp;&amp; this.mwst.get() == other.getMwst()
              &amp;&amp; this.preis.get() == other.getPreis()
              &amp;&amp; this.isRetourMoeglich.get() == other.isIsRetourMoeglich()) {
          return true;
      }*/
  
      if (this.produktid.get() == other.getProduktid()) {
          return true;
      }
      }else if (obj instanceof String){
          if(((String)obj).equals(this.getBezeichnung()))
              return true;
      }
      return false;
  }
  </code></pre>
  
  <p>}</p>