What is the "cannot find symbol" error in Java?
The “cannot find symbol” error is caused when a user references a variable that is not declared in the program. In simpler words, the compiler is unaware of any declaration of said variable.
class HelloWorld {public static void main( String args[] ) {int a = 5;int b = 4;// product is not declared. This will show an error.product = a * b;}}
How to fix the error
You should check the code for the following scenarios if you ever come across this error:
-
Check if you have declared the variable, i.e.,
int i = 3;. If someone has not writtenint, then the error may appear. Also, check if the variable declared is outside the code, e.g., if it is not part of the HelloWorld class. -
Ensure that you are using the correct case. An example could be if you declared the variable as
varbut are accessing it asVar. -
Identifier values like numbers, dollar signs, and hyphens are not allowed – check for them.
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved