1

While I was coding, I added the following piece of code:

nameComboBox.valueProperty().addListener(new ChangeListener<NameVO>() {

        @Override
        public void changed(
                ObservableValue<? extends NameVO> observable,
                NameVO oldValue, NameVO newValue) {
            // TODO Auto-generated method stub

        }
    });


And the Eclipse is showing me Red line under addListener and moving mouse over that I could see the following message:

The method addListener(ChangeListener<? super capture#6-of ?>) in the type ObservableValue<capture#6-of ?> is not applicable for the arguments (new ChangeListener<NameVO>(){})

Why would this be because of?

[Note: I have done similar thing for remaining ComboBoxes, but I am getting no such message over there]

4

3 回答 3

0

它似乎是期待ObservableValue<NameVO>而不是ObservableValue<? extends NameVO>

首先,看看你是如何明确声明你的类型参数的ChangeListener

new ChangeListener<NameVO>{ .... }

您明确说明它是,NameVO但是当您实际去实现该方法时,您将其更改为? extends NameVO

于 2013-08-27T23:54:28.337 回答
0

得到解决方案!

对于所有其他 ComboBoxes,声明涉及各自的值对象。

例如:

@FXML //  fx:id="projectComboBox"
private ComboBox<ProjectVO> projectComboBox; // Value injected by FXMLLoader

但是,nameComboBox被简单地声明为:

@FXML //  fx:id="nameComboBox"
private ComboBox<?> nameComboBox; // Value injected by FXMLLoader

NameVO在的地方添加?并摆脱了问题。

于 2013-08-28T00:08:47.757 回答
-1

The answer is simple, just add the below to your import

import javafx.scene.control.Toggle;
于 2017-10-17T14:38:55.163 回答