• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Netbeans headaches

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey folks, I have this source file here.
When I try to compile it in Netbeans 5.5 (Mac), I get errors in my inner class methods which seem to indicate that the inner classes can't access the variables, etc of the outer class. Can someone help me determine what I'm doing wrong?



To summarize, it should create a window with a panel - the panel has a little icon on it that should move when I press the arrow keys on my keyboard. I'm fine with debugging once the code works, but this is ht I get when I try to compile the beast:


Compiling 1 source file to /Users/Bex/javawork/practiceapp1/build/classes
/Users/Bex/javawork/practiceapp1/src/practiceapp1/Main.java:59: cannot find symbol
symbol : variable x
location: class practiceapp1.Main.MacListener
x--;
/Users/Bex/javawork/practiceapp1/src/practiceapp1/Main.java:62: cannot find symbol
symbol : variable y
location: class practiceapp1.Main.MacListener
y--;


etc, etc.

Any help
[ March 28, 2007: Message edited by: Kaleey James ]
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This has nothing to do with Netbeans. This is basic programming 101. Variable Scope. You decared your x and y variables in the main method which makes them "local variables". The only place those variables have scope is within the main method. Make them "member variables" so they are available at the class level.

Also, if you are going to declare variables with an initial value, you might as well do it on one line so...

int x = 20;

rather than

int x;
x = 20;

And I moving this to the Java In General (Beginner) forum.
 
Kaleey James
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
bleep bleep bleep!!!

I should have seen that - sorry, been a bit rusty.
I thought I tried that already. If it doesn't fix my problem (or I get a new one), I'll post with updates.

Thanks!



~KJ
 
reply
    Bookmark Topic Watch Topic
  • New Topic