Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find symbol println

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.

like image 665
ellman121 Avatar asked Jul 30 '13 22:07

ellman121


People also ask

What to do if Cannot find symbol in Java?

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.

What is Cannot find symbol error?

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.

What does “cannot find symbol” mean?

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.

Why can't I find the symbol in Java?

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).

Why can't I find the symbol for a class?

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 ...


1 Answers

You concatenate Strings with + not ,

System.out.println("You have ", numGuards, " guards");

Should become

System.out.println("You have " + numGuards + " guards");
like image 199
Kon Avatar answered Sep 30 '22 06:09

Kon