Home Java Java-get-example Java error cannot find symbol
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Java error cannot find symbol

Advertisement
Whenever a Compiler does not recognize a class name, Java displays an error ?cannot find symbol?.

Whenever a Compiler does not recognize a class name, Java displays an error “cannot find symbol”.

The reason behind cannot find symbol error is:

  • A programmer has misspelled the name of the class.
  • A programmer didn’t Imported the class name.

Following example will help you understand the java error cannot find symbol. In this example a class name 'cannot find symbol' is used.

int variable “w” and “x” with respective values have been initialized. int “y” stores the sum of their value.

The System.out.println is used to print the output. But programmer instead of writing “y”, wrote variable “z”.

The compiler did not recognize a variable “z” and displays an error “Java error cannot find symbol”.

Cannotfindsymbol.java

import java.lang.*;
public class Cannotfindsymbol {
public static void main(String[] args) {
try{
int w=10;
int x=3;
int y=w+x;
System.out.println(z);
}
catch(Exception ex){
System.out.println(ex);
}
}
}

Output:

/home/girish/NetBeansProjects/errors/src/
Cannotfindsymbol.java:11: cannot find symbol

symbol: variable z
location: class Cannotfindsymbol
System.out.println(z);
1 error0

*To remove this error you have to declare the variable z.

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: May 8, 2013

Ask Questions?    Discuss: Java error cannot find symbol  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com