
the use of homoglyphs in identifier construction that are difficult to tell apart.redefining platform or library classes with the same name.building a project with an older JDK version.using dependencies with old or incompatible versions.Declaring this variable by specifying its data type (or, alternatively, inferring its type with the var keyword in Java 10+) resolves the issue (Fig. 1(a) shows how an undeclared variable, in this case the identifier average on line 9, results in two instances of the cannot find symbol error, at the positions where they appear in the code. Unlike some other languages that don’t require explicit declaration of variables, or may allow declaring a variable after it has been referenced (via hoisting ), Java requires declaring a variable before it can be used or referenced in any way.įig. Consequently, the most common occurrence of this error is when there is a reference to an undeclared variable. When the Java compiler encounters a use of an identifier which it cannot find in the symbol table, it raises the cannot find symbol error. Besides the naming, there is no difference between what these terms stand for.Ĭannot Find Symbol Error Examples Undeclared variable out-of-scope references to variables and methods Ĭannot Find Symbol vs Symbol Not Found vs Cannot Resolve SymbolĪs different Java compilers use slightly different terminology, the cannot find symbol error can also be found under the terms symbol not found and cannot resolve symbol.missing variable and method declarations.



The most common triggers for the cannot find symbol compile-time error include:

Symbol tables are also used for code generation and optimization. When uses of these identifiers are encountered in the source code, the compiler looks them up in the symbol tables and relies on this information for things such as verifying that a variable has been declared, determining the scope of a variable, and verifying that an expression is semantically correct with type checking. As the declarations of classes, interfaces, variables, and methods are processed, their identifiers are bound to corresponding entries in the symbol tables. This information is entered into the symbol tables during lexical and syntax analysis and is used in the later phases of compilation. Symbol tables are an important data structure created and maintained by compilers to store information associated with identifiers in a given source code.
