I just started a new java project today, and I'm having a problem with println. Here's my main method:
public static void main(String[] args) {
String stringNumGuards = JOptionPane.showInputDialog("How any guards do you have?");
int numGuards = Integer.parseInt(stringNumGuards);
Controller headGuard = new Controller();
System.out.println("You have ", numGuards, " guards");
} //main
The javac output
Controller.java:10: cannot find symbol
symbol : method println(java.lang.String,int,java.lang.String)
location: class java.io.PrintStream
System.out.println("You have ", numGuards, " guards");
What did I do wrong? I've never had problems with println before.
Output. 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.
The cannot find symbol error, also found under the names of symbol not found and cannot resolve symbol , is a Java compile-time error which emerges whenever there is an identifier in the source code which the compiler is unable to work out what it refers to.
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.
The root cause for the cannot find symbol Java error can occasionally be found in some unexpected or obscure places. Such is the case with accidental semicolons that terminate a statement ahead of time (Fig. 5), or when object creation is attempted without a proper constructor invocation which has to have the new keyword (Fig. 6).
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 ...
You concatenate Strings with +
not ,
System.out.println("You have ", numGuards, " guards");
Should become
System.out.println("You have " + numGuards + " guards");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With