I have an issue. I want to use my object which is outside a button, and I get an error message:
Local variable es defined in an enclosing scope must be final or effectively final
File inputfile = new File("./input.txt");
testobject to = null;
try {
Scanner inputscan = new Scanner(inputfile);
String text1 = inputscan.nextLine();
String text2 = inputscan.nextLine();
to = new testobject(text1,text2);
inputscan.close();
} catch (Exception e) {
System.err.println(e);
}
JButton btnSave = new JButton("Save");
btnSave.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
to.setSomething("test");
}
});
Obviously, I have a class with a constructor etc... but I have a problem that I cant reach my object inside the button.