method call error

Uh… and when I thought I’ve seen it all.
This is my first error of this kind, what does it mean? I can’t call methodes like this (in definition)?

[quote=“Eclipse Error”]Cannot refer to a non-final variable network inside an inner class defined in a different method
[/quote]


	    Runtime.getRuntime().addShutdownHook(new Thread() {
		    public void run() { 
		        running = false;
		        network.stopServer(); // - THE ERROR HERE
		        System.out.println("Shutdown hook executed");
		        finishOff();
		    }
		});

First time working with inner-classes?

[running] is not a final variable (if it was, you couldn’t set it to false)

maybe the same applies to the [network] variable.


JButton but = new JButton();
JTextField txt = new JTextField();

but.addActionListener(new ActionListener()
{
   public void actionPerformed(ActionEvent event)
   {
       txt.setText("button pressed"); // this is impossible, as long as txt is not final.
   }
});

this is because the class can’t possibly know wenn the variable changes, because the inner class doesn’t hold the variable.

oh I see…
I guess I’ll just call a method from class that holds the variable to change it.