-1

I don't know how to solve below problem. I have got a code like below:

public class MyWindow{
    private Button saveButton;
    private Application saveImplementation;
    void createSaveButton() {
        saveButton.addListener(new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                this.saveImplementation.save();//Cannot resolve symbol 'saveImplementation'
            }
        });
    }
}

In saveButton.addListener I cannot refer to saveImplementation, which is a field of class MyWindow - can you help me? How can I solve it?

GhostCat
  • 137,827
  • 25
  • 176
  • 248
user2856064
  • 541
  • 1
  • 8
  • 25
  • can you also post the error ? – Ravi Mar 27 '17 at 09:30
  • You need MyWindow.this --- you are inside an **inner** class; so "this" alone points to the "wrong" class. – GhostCat Mar 27 '17 at 09:33
  • And hint: you are grossly overtagging. This has **nothing** todo with field, lambdas, vaadin whatever. – GhostCat Mar 27 '17 at 09:34
  • The error occurs because you have just declare object saveImplementation and not yet instantiate it using new keyword.Just add this line to your 3 line. private Application saveImplementation=new Application(); – bit-shashank Mar 27 '17 at 09:35
  • Ok, thank you I will try to remove this question. – user2856064 Mar 27 '17 at 09:36
  • @javafan Wrong. He is right now dealing with a compilation error. That NullPointerException because not initialized comes later, when he would be able to **run** that code. – GhostCat Mar 27 '17 at 09:36

1 Answers1

2

this refers to the ClickListener's instance. You need to specify the MyWindow's instance via MyWindow.this.saveImplementation.save();

Stefan Warminski
  • 1,845
  • 1
  • 9
  • 18