I\'ve been trying to figure this out, I\'ve run it in different programs so it\'s definitely in the code. Probably something easy too. The error says
It can't find the variable password
, which, as you've coded it, only exists in the Password2
constructor. You'll need to either make password
a class member variable or pass it to the constructor of your Handler
classes, so they can have a reference to it.
password
is a local variable declared in the constructor of Password2. It is not in scope in your EnterButtonHandler.actionPerformed method
. Make it an instance variable to resolve.
Read the error message, love the error message.
It takes some practice, but after awhile it's easy to see it more clearly: just read across the bold text below as a sentence :)
error: cannot find symbol [...]
symbol: variable password
location: [in] class Password2.EnterButtonHandler
There is nothing named password
in that scope/context (EnterButtonHandler
).
Happy coding.
Hint: there is a local variable with the same name in a different scope/context... perhaps it shouldn't be a local variable? See The Java Tutorial: Variables for more :)
Your class doesn't have a definition for password
. Hence, the error when passing it to the equals
method.
password
is local to the Password2
constructor.
It should either be passed around, or an instance variable.