
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
What can cause the "cannot find symbol" error in Java?
The “cannot find symbol” error occurs mainly when we try to reference a variable that is not declared in the program which we are compiling, it means that the compiler doesn’t know the variable we are referring to.
Some possible causes for “Cannot find symbol” to occur are
- Using a variable that is not declared or outside the code.
- Using wrong cases (“tutorials” and “Tutorials" are different) or making spelling mistakes.
- The packaged class has not been referenced correctly using an import declaration.
- Using improper identifier values like letters, numbers, underscore and dollar sign. The hello-class is different from helloclass.
Example
public class CannotFindSymbolTest { public static void main(String[] args) { int n1 = 10; int n2 = 20; sum = n1 + n2; System.out.println(sum); } }
Output
CannotFindSymbolTest.java:5: error: cannot find symbol sum = n1 + n2; ^ symbol: variable sum location: class CannotFindSymbolTest CannotFindSymbolTest.java:7: error: cannot find symbol System.out.println(sum); ^ symbol: variable sum location: class CannotFindSymbolTest
In the above program, "Cannot find symbol" error will occur because “sum” is not declared. In order to solve the error, we need to define “int sum = n1+n2” before using the variable sum.
- Related Articles
- What can cause a Cannot find symbol error in java?
- TestNG error:- Cannot find class in classpath using Selenium
- What is the cause of NoSuchElementException and how can we fix it in java?
- Error while selecting into field-symbol in SAP ABAP
- Error codes, cause and example of deadlock in DB2
- What is an OutOfMemoryError and steps to find the root cause of OOM in Java?
- Python: Cannot understand why the error - cannot concatenate 'str' and 'int' object ?
- Can Stress Cause Hives?
- What is the cause of diabetes? How it can be controlled?
- Can we use the “.” symbol in MongoDB collection name?
- Can a microwave cause cancer?
- Unreachable Code Error in Java
- Thread Interference Error in Java
- Memory Consistency Error in Java
- What is the Symbol Table?

Advertisements