Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java

What is the "cannot find symbol" error in Java?

Sarvech Qadir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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:

  1. Check if you have declared the variable, i.e., int i = 3;. If someone has not written int, 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.

  2. Ensure that you are using the correct case. An example could be if you declared the variable as var but are accessing it as Var.

  3. Identifier values like numbers, dollar signs, and hyphens are not allowed – check for them.

RELATED TAGS

java

CONTRIBUTOR

Sarvech Qadir
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring