Typos

Make sure that the symbol you are trying to reference is spelled correctly and matches the case used in the definition.

Example 1:

Java




// Java Program to demonstrate typos
public class Main {
    static int Large(int a, int b)
    {
        if (a > b) {
            return a;
        }
        else if (b > a) {
            return b;
        }
        else {
            return -1;
        }
    }
  
    public static void main(String... args)
    {
        int value = large(20, 4);
        System.out.println(value);
    }
}


Output:

./Main.java:17: error: cannot find symbol
        int value = large(20, 4);
                    ^
  symbol:   method large(int,int)
  location: class Main

Explanation of the above program

We get this error as the function we initialized is Large(int a,int b) whereas we are calling large(a,b) so to resolve this typo mistake we just change large to Large.

Example 2:

Java




// Java Program to print largest number
public class Main {
    static int Large(int a, int b)
    {
        if (a > b) {
            return a;
        }
        else if (b > a) {
            return b;
        }
        else {
            return -1;
        }
    }
  
    public static void main(String... args)
    {
        // function call
        int value = Large(20, 4);
        System.out.println(value);
    }
}


Output

20

How to Resolve The Cannot Find Symbol Error in Java?

The Cannot Find Symbol Error in Java error occurs when the Java compiler cannot find a symbol that you are trying to reference in your code. In this article, we will explore how to resolve the “Cannot Find Symbol” error in Java.

The “Cannot Find Symbol” error occurs when you are trying to reference a symbol that has not been defined or imported properly. Symbols can include variables, methods, and classes or in easy language when you try to reference an undeclared variable in your code. The error typically occurs when you have made a typo, used the wrong case in the symbol name, or when you are trying to reference a symbol that is out of scope. You may also encounter this error when you are using multiple files, and the compiler cannot find a class or package that you are trying to reference.

Common mistakes that lead to “Cannot Find Symbol” error in Java and resolving them, you can follow these steps:

  • Typos
  • Undeclared Variable
  • Scope of Current block
  • Import Statement

Similar Reads

Typos

Make sure that the symbol you are trying to reference is spelled correctly and matches the case used in the definition....

Undeclared Variable

...

Check the scope

...