Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Errors in addListener method

Valentin Grigoriev
9 years ago Jul 05, 2012 1:45pm

Hello.

I do exercises from the book "Book of Vaadin".
I don't know why there are errors in the next example:

import com.vaadin.Application;
import com.vaadin.ui.*;

CheckBox switchEditable = new CheckBox("Editable");
switchEditable.addListener(new Property.ValueChangeListener() {
	public void valueChange(ValueChangeEvent event) {			
	}
	});

Errors:
[list=3]

  • The method addListener(Button.ClickListener) in the type Button is not applicable for the arguments (new ValueChangeListener(){})
  • Property cannot be resolved to a type
  • ValueChangeEvent cannot be resolved to a type
  • I think, I have to import something. But I don't know what.

    Last updated on Jul, 5th 2012
    Jens Jansson
    9 years ago Jul 05, 2012 2:17pm
    import com.vaadin.data.Property;
    import com.vaadin.data.Property.ValueChangeEvent;

    I usually write it in form:

    switchEditable.addListener(new ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
        }
    });

    (missing "Property." in Listener)
    which means that the import would be:

    import com.vaadin.data.Property.ValueChangeEvent;
    import com.vaadin.data.Property.ValueChangeListener;

    Guessing from your error messages, I'd guess you are using Eclipse, correct? In eclipse you can press ctrl+shift+o, which tries to resolve the imports, and gives you an list of possibilities if there are multiple that match. Very handy tool.

    Henri Sara
    9 years ago Jul 06, 2012 6:51am
    Valentin Grigoriev
    9 years ago Jul 06, 2012 7:07am