Java error cannot find symbol

Java cannot find symbol occur when compiler has not enough information about what java code trying to execute.

Java error cannot find symbol

Java cannot find symbol occur when compiler has not enough information about what java code trying to execute.

Java error cannot find symbol

Java error cannot find symbol

In this section you will learn about "cannot find symbol" in java. Java cannot find symbol is a type of error occurs when a compiler has not enough information about the variable, class or method name  you used in program. When a java program is being compiled then compiler create a list of variables in use. If it can't find the variable in use its trying to refer, then it will give a error cannot find symbol.

Reason for cannot find symbol is as follows:

  • When trying to use a variable without declaring it.
  • Misspelling of class or method name.
  • Package class used has not being referenced correctly using import declaration.
  • When parameter used do not matched in method signature.

Example : The following code illustrates what is cannot find symbol :

    public class CannotFindSymbol {
   public static void main(String args)
  {
   int a,b;
   System.out.printl("value of a"+a);
   }
}

Output : When you compile and execute the program output will be as below

Description : In the above program system.out.println() will confuse compiler and give error cannot find symbol because System.out class does not have method "printl"