Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Netbeans headaches  RSS feed

 
Kaleey James
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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 ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!