Compiler Error: cannot find symbol

The "Cannot find symbol" errors generally occur when you try to reference an undeclared variable in your code. A "Cannot find symbol" error means that the compiler cannot do this. Your code appears to be referring to something that the compiler doesn't understand. When your code is compiled, the compiler needs to work out what each and every identifier in your code means. As the compiler is going through the code it will find something and know what to do with it or not. Your Cannot find symbol error relates to the identifiers and means that Java cannot figure out what the "symbol" means. Example
public class TestClass { public static void main(String[] args) { int x = 2; int y = 4; sum = x + y ; System.out.println(sum); } }
output
TestClass.java:10: error: cannot find symbol sum = x + y ; symbol: variable sum location: class TestClass TestClass.java:11: error: cannot find symbol System.out.println(sum); symbol: variable sum location: class TestClass 2 errors
In the above code, the variable sum has not been declared, you need to tell the compiler what the type of sum is; for example:
int sum = x + y ;
The general causes for a Cannot find symbol error are things like:
  1. Incorrect spelling.
  2. Wrong case. Halo is different from halo.
  3. Improper use of acceptable identifier values (letters, numbers, underscore, dollar sign), my-class is not the same as myclass.
  4. No variable declaration or variable is outside of the scope you are referencing it in.

Looking for a Java Developer job ?

Click Here