What does a Cannot find symbol or Cannot resolve symbol error mean?
Data Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.
When programming in Java or using similar languages supporting static type checking, you might encounter the error messages "Cannot find symbol" or "Cannot resolve symbol". These errors are compile-time issues that indicate the compiler cannot recognize a reference to a symbol, where a symbol can be a variable, method, class, or package name.
Understanding the Error
The "Cannot find symbol" error is commonly seen when using the Java Development Kit (JDK) to compile Java code. This error points out that the Java compiler cannot recognize a symbol that is being referred to in your code. This usually suggests a few potential problems:
- Spelling Mistakes: The most common cause is simple typos or spelling mistakes in your code.
- Incorrect import statements: If the symbol is a class or a package that you are trying to use, it could be that you have not imported it correctly, or at all.
- Scope of the symbol: Perhaps the variable is declared in a different scope from which it is being accessed.
- Library not linked: If the symbol belongs to a library, the library may not be properly linked or added to the project’s build path.
Common Scenarios and Examples
1. Variable Mismatch
If you declare a variable with one name but use a different name later on, you will encounter this error.
2. Method Name Typo
Similarly, calling a method with an incorrect name will result in this error.
3. Incorrect Import
Using a class without the appropriate import statement, or importing it incorrectly, can also lead to this error.
4. Class or Package Not Found
If you refer to a class that does not exist or is not in the classpath, this will trigger the error.
Resolving the Error
To solve a "Cannot find symbol" error, you will need to:
- Verify spelling and case sensitivity: Ensure all identifiers are spelled correctly and cases are respected.
- Correct imports: Confirm that all import statements are correctly spelled and refer to valid classes or packages.
- Ensure library dependencies are properly added to your project’s build path: If the symbol is from a library, ensure the library is correctly linked.
Debugging Tips
- Check the line number: The error message provides a line number that directs you where to look.
- Use an IDE: Integrated Development Environments (IDEs) like IntelliJ IDEA or Eclipse offer features like code suggestions that can prevent this error.
- Read the environment setup documentation: Make sure the project setup, including libraries and dependencies, matches the requirements.
Summary Table
| Issue Type | Common Causes | Example | Solution |
| Spelling Mistakes | Typo in variable, method, or class | int numbr = 10; | Check spelling, particularly of identifiers. |
| Incorrect Import Statements | Wrong or missing import | import java.utl.ArrayList; | Fix imports to properly reference classes/packages. |
| Scope Issues | Variable not in scope | Using a local variable outside its scope | Verify variable declaration and usage scope. |
| Library or Classpath Issues | Missing libraries or classpath issue | NonExistentClass obj; | Add necessary libraries and ensure they are linked. |
By knowing how to identify and resolve the "Cannot find symbol" error, you can streamline your development process and reduce potential frustrations during Java project compilation.
Related reading
- What does 'antMatchers' mean?
- What does Class? mean in Java?
- What does Cookie CsrfTokenRepository.withHttpOnlyFalse do and when to use it?
- What does it mean The serializable class does not declare a static final serialVersionUID field?
- What does a successful MySQL DELETE return? How to check if DELETE was successful?
- What does Broker transport failure mean in kafka?
- What does Java option -Xmx stand for?
- What does java.lang.Thread.interrupt() do?

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.