btnButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
var1 = Float.parseFloat(txtBox.getText());
}
catch(NumberFormatException n) {
}
}
});
我不能訪問到變量「VAR1」在這裏,我得到的錯誤:訪問變量的ActionEvent級
local variable var1 is accessed from within inner class; needs to be declared final
我如何可以訪問變量actionPerformed事件?聲明爲final不是有用的,因爲更改最終變量值是不可能的。
1)'趕上(NumberFormatException的N) { }形式'趕上(例外五的'變化代碼){ ..'到'catch(Exception e){e.printStackTrace(); //非常翔實! ..'2)爲了更好的幫助,請發佈[SSCCE](http://sscce.org/)。 –