Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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 796 times)
0 Members and 1 Guest are viewing this topic.
Offline Kova

Senior Member





« 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();
          }
      });
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 797
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 Member


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 Member





« 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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (23 views)
2014-09-12 09:08:26

Norakomi (56 views)
2014-09-10 13:57:51

TehJavaDev (69 views)
2014-09-10 06:39:09

Tekkerue (34 views)
2014-09-09 02:24:56

mitcheeb (56 views)
2014-09-08 06:06:29

BurntPizza (40 views)
2014-09-07 01:13:42

Longarmx (25 views)
2014-09-07 01:12:14

Longarmx (32 views)
2014-09-07 01:11:22

Longarmx (31 views)
2014-09-07 01:10:19

mitcheeb (39 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!