【发布时间】:2017-08-19 22:33:19
【问题描述】:
我不知道如何解决以下问题。 我有如下代码:
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'
}
});
}
}
在 saveButton.addListener 中我不能引用 saveImplementation,它是 MyWindow 类的一个字段 - 你能帮帮我吗? 我该如何解决?
【问题讨论】:
-
你也可以发布错误吗?
-
你需要 MyWindow.this --- 你在一个 inner 类中;所以“this”单独指向“错误”类。
-
并提示:您严重过度标记。这与字段、lambda、vaadin 等没有任何关系。
-
发生错误是因为您刚刚声明了对象 saveImplementation 并且尚未使用 new 关键字实例化它。只需将此行添加到您的 3 行。私有应用程序 saveImplementation=new Application();
-
好的,谢谢,我会尝试删除这个问题。