Question

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]

Was it helpful?

Solution 2

Got the solution!

For all other ComboBoxes, the declaration involved the respective value object.

For example:

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

But, nameComboBox was simple declared as:

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

Added NameVO at the place of ? and got rid of the problem.

OTHER TIPS

It appears to be expecting ObservableValue<NameVO> as opposed to ObservableValue<? extends NameVO>.

To start off, look at how you are explicitly stating the type argument for your ChangeListener:

new ChangeListener<NameVO>{ .... }

You are explicitly stating that it is NameVO but when you actually go to implement the method, you are changing it to ? extends NameVO

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

import javafx.scene.control.Toggle;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top