Java Reference
In-Depth Information
this error message, which in this example is the symbol that it can't find, and
some more information about the location of the missing symbol.
So on line 21 of , Java doesn't know about the thing named
MessageReceiver . Let's look at some possible causes.
javac: Cannot Find Symbol
“Cannot find symbol” means that the compiler has come across a word, a
piece of text, that it doesn't understand.
This error can be caused by several problems. First, what happens if I just
stick in an assignment statement like i=10 without ever declaring what i is?
src/helloworld/ cannot find symbol
symbol : variable i
location: class helloworld.HelloWorld
i = 10;
The compiler has no idea what i is or what it should be, so it complains.
To fix it I can add a declaration like int i; above this code or on the same line
as inti=10; . Now the compiler knows that i is a local variable.
But what if I have declared the variable and I still get an error? For instance,
in the call to helloCommand , I'm declaring a parameter MessageReceivercaller . caller
is my variable, of type MessageReceiver , but I get the same error:
src/helloworld/ cannot find symbol
symbol : class MessageReceiver
location: class helloworld.HelloWorld
public void helloCommand(MessageReceiver caller, String[] parameters)
This can indicate a missing or misspelled import statement. The compiler
knows that caller is a variable of type MessageReceiver , but it doesn't know what
a MessageReceiver is.
In this case, adding
at the top of the file fixes the error. See Appendix 7, Common Imports , on page
253 , for a list of common imports we've used in the topic, or look it up in the
Java or Canary doc.
Search WWH ::

Custom Search