Mainly occurs when we try to reference a variable that is not declared in the program we are compiling "Symbol not found" error, which means The compiler has no idea what variables we are referencing.
public class CannotFindSymbolTest { public static void main(String[] args) { int n1 = 10; int n2 = 20; sum = n1 + n2; System.out.println(sum); } }
CannotFindSymbolTest.java:5: error: <strong>cannot find symbol </strong>sum = n1 + n2; ^ symbol: variable sum location: class CannotFindSymbolTest CannotFindSymbolTest.java:7: error: <strong>cannot find symbol</strong> System.out.println(sum); ^ symbol: variable sum location: class CannotFindSymbolTest
In the above program, "Find Symbol not found" error because " sum" was not declared. To solve this error, we need to define "int sum = n1 n2" before using the variable sum.
The above is the detailed content of What are the causes of 'cannot find symbol' errors in Java?. For more information, please follow other related articles on the PHP Chinese website!