This discussion is archived
2 Replies Latest reply: Nov 21, 2012 12:04 PM by 972881 RSS

Incompatibel type? assigning IntegerProperty to ObservableValue<Integer>

972881 Newbie
Currently Being Moderated
Hi,
why do i get an incompatibel type error on assigning an IntegerProperty to an ObservableValue<Integer>, but not on assigning an StringProperty to an Observable<String> ??? And how to return an ObservableValue<Integer> from an IntegerProperty ?
class BmsRemoteSensingUnit {  
     private StringProperty text;
     public void setText(String value) { textProperty().set(value); }
     public String getText() { return textProperty().get(); }
     public StringProperty textProperty() { 
         if (text == null) {
             text = new SimpleStringProperty(this, "text");
         }
         return text; 
     }
     
     private IntegerProperty serialNumber;
     public void setSerialNumber(Integer value) { serialNumberProperty().set(value); }
     public Integer getSerialNumber() { return serialNumberProperty().get(); }
     public IntegerProperty serialNumberProperty() { 
         if (serialNumber == null) {
             serialNumber = new SimpleIntegerProperty(this, "serialNumber");
         }
         return serialNumber; 
     }
}


        textCol.setCellValueFactory(new Callback<CellDataFeatures<BmsRemoteSensingUnit, String>, ObservableValue<String>>() {
             @Override
             public ObservableValue<String> call(CellDataFeatures<BmsRemoteSensingUnit, String> p) {                         
                 return p.getValue().getName();
             }
          });
                
        serialNumberCol.setCellValueFactory(new Callback<CellDataFeatures<BmsRemoteSensingUnit, Integer>, ObservableValue<Integer>>() {          
            @Override
            public ObservableValue<Integer> call(CellDataFeatures<BmsRemoteSensingUnit, Integer> p) {               
                return p.getValue().serialNumberProperty();                // #####    Incompatibel Type Error   #####
            }
         });
// Error:
error: incompatible types
   return p.getValue().serialNumberProperty();
  required: ObservableValue<Integer>
  found:    IntegerProperty
Edited by: Magonline on 09.11.2012 08:19 Question modified.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points