Java Error Messages Tutor
cannot find symbol - variable


Error:

    cannot find symbol
    symbol  :  variable
<variable name>

Explanation:

The compiler has found a variable name that it doesn't recognize or a method call that is missing parentheses.

Checklist:

  • Have you declared the variable named in the message?

  • Is the variable name spelled exactly the same as you declared it? Check for typos, including capitalization. Remember that Java identifiers are case-senstive.

  • Are you calling a method without including the parentheses for the argument list? Parentheses are required even if the method takes no arguments.

Examples:

With the following statements in a source file named Average.java:

8 double averageGrade; // averageGrade is declared here
...
25 averagegrade = totalGrades / countOfGrades;
// Note that averageGrade is spelled here without a capital G

the Java compiler would generate the following error:

Average.java:25: cannot find symbol
symbol : variable averagegrade
location: class Average
    averagegrade = totalGrades / countGrades;
    ^

Also, with the following statements in a source file named CountLetters.java:

11 String greeting = "Hello";
12 int len = greeting.length;   // Note that parentheses are missing after length

the Java compiler would generate the following error:

CountLetters.java:12: cannot find symbol
symbol : variable length
location: class java.lang.String
int len = greeting.length;
                  ^

Without parentheses, length appears to be a variable name, not a method. To fix this problem, change line 12 to the following:

int len = greeting.length( );

Back to main page