Program not compiling. "cannot find symbol"

Caporegime
Joined
12 Mar 2004
Posts
29,962
Location
England
For some reason my PumpConsole class won't compile, I keep getting the cannot find symbol error for the System.out.println statement.


Does anyone know why?
 
Last edited:
That'll be because d1 though d5 are locally scoped variables and don't exist outside the method they're declared in. You need to make them class variables.
 
It is a scoping issue.

d1 is defined locally in setlcddisplay() and so will not be available outside of that method. You need to define it as an instance variable to use it as you wish to.

Code:
class MyClass {
  int myInstanceVariable;

  void method1() {
    myInstanceVariable = 10;
  }

  void method2() {
    System.out.println(myInstanceVariable);
  }
}
 
Back
Top Bottom