Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (684)
Games in Android Showcase (196)
games submitted by our members
Games in WIP (752)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  method call error  (Read 1140 times)
0 Members and 1 Guest are viewing this topic.
Offline Kova

Senior Devvie





« Posted 2006-04-07 11:18:07 »

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 from: Eclipse Error
Cannot refer to a non-final variable network inside an inner class defined in a different method

1  
2  
3  
4  
5  
6  
7  
8  
       Runtime.getRuntime().addShutdownHook(new Thread() {
          public void run() {
              running = false;
              network.stopServer(); // - THE ERROR HERE
              System.out.println("Shutdown hook executed");
              finishOff();
          }
      });
Online Riven
Administrator

« JGO Overlord »


Medals: 1228
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2006-04-07 11:37:55 »

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.



1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
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.
   }
});

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline Mr_Light

Senior Devvie


Medals: 1


shiny.


« Reply #2 - Posted 2006-04-07 13:52:44 »

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

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Kova

Senior Devvie





« Reply #3 - Posted 2006-04-07 16:31:40 »

oh I see...
I guess I'll just call a method from class that holds the variable to change it.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 
orrenravid (260 views)
2016-07-16 03:57:23

theagentd (329 views)
2016-07-11 14:28:54

Hydroque (418 views)
2016-07-06 05:56:57

Hydroque (577 views)
2016-07-03 08:52:54

GrandCastle (435 views)
2016-07-01 09:13:47

GrandCastle (427 views)
2016-07-01 09:09:45

CopyableCougar4 (481 views)
2016-06-25 16:56:52

Hydroque (444 views)
2016-06-22 02:17:53

SwampChicken (408 views)
2016-06-20 13:22:57

SwampChicken (311 views)
2016-06-20 13:22:49
Making a Dynamic Plugin System
by Hydroque
2016-06-25 00:13:25

Java Data structures
by BinaryMonkL
2016-06-13 21:22:09

Java Data structures
by BinaryMonkL
2016-06-13 21:20:42

FPS Camera Tutorial
by Hydroque
2016-05-22 05:40:58

Website offering 3D Models specifically for games for free
by vusman
2016-05-18 17:23:09

Website offering 3D Models specifically for games for free
by vusman
2016-05-09 08:50:56

Website offering 3D Models specifically for games for free
by vusman
2016-05-06 11:10:21

Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!