*
The moose likes Beginning Java and the fly likes can not find symbol Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "can not find symbol" Watch "can not find symbol" New topic
Author

can not find symbol

uzair ahmed
Greenhorn

Joined: Nov 14, 2012
Posts: 10
I have two classes
[Added code tags - see UseCodeTags for details]

/*
i am getting this error : can not find symbol
Bishop pie = new Bishop();
symbol: class Bishop
location: class Main
and the same error for the constructor
error : can not find symbol
Bishop pie = new Bishop();
symbol: class Bishop
location: class Main
what should i do now ?*/
Stuie Clarky
Ranch Hand

Joined: Nov 09, 2012
Posts: 73

If this is a full copy of your source code, how does your main class (class 1) know about the Bishop class?


OCAJP 7
uzair ahmed
Greenhorn

Joined: Nov 14, 2012
Posts: 10
the main class and Bishop class is in the same Folder so according to me no need to tell the Main that where is Bishop class
and also i am making an object pie
as i know we use objects to communicate the classes .so there is no need for main class (class 1) to know about the Bishop class.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4343
    
    8

That depends on how you're trying to compile it. You need to make sure you're telling the compiler to look in the current directory. What command are you using to compile at the moment?

And Stuie: welcome to the Ranch!
uzair ahmed
Greenhorn

Joined: Nov 14, 2012
Posts: 10
i am using
javac Main.java
to compile
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37958
    
  22
Why have you got two main methods? How do you manage to use the super keyword in the main method? You can’t use super in a static context. You probably want that lot in an instance method called move.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4343
    
    8

uzair ahmed wrote:i am using
javac Main.java
to compile

Thought so. You need to tell the compiler to look in the current directory for other classes by specifying a classpath. Try this:

javac -cp . Main.java

('.' means 'current directory')

Once it's working you're going to run into compiler errors, as Campbell says, but getting the error messages is a good first step.
uzair ahmed
Greenhorn

Joined: Nov 14, 2012
Posts: 10
i am getting the same error again
error : can not find symbol
Bishop pie = new Bishop();
symbol: class Bishop
location: class Main
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37958
    
  22
Welcome to the Ranch

I think you may have another error, namely that you have set a system classpath. Even though people tell you to set one, that is usually a mistake. If you set the classpath yourself, delete it altogether.
If you did not set a classpath, but there was one already set, add .; (windows) or .: (Unix/Mac/Linux) to its beginning.
uzair ahmed
Greenhorn

Joined: Nov 14, 2012
Posts: 10
i set it my self
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem\;C:\Program Files\Java\jdk1.7.0_09\bin
after delete it altogether this remains
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem\

but this didn't work also
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4343
    
    8

Are you sure you haven't just changed the PATH rather than the CLASSPATH?

The PATH is where your operating system looks for applications. You generally want your Java binary folder to be on it so you can just refer to java and javac rather than the full path. The CLASSPATH is where javac looks for other classes.
uzair ahmed
Greenhorn

Joined: Nov 14, 2012
Posts: 10
from this method i set the path
system properties > Advanced > Environment Variable > System variable
variable=Path
value=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem\;"C:\Program Files\Java\jdk1.7.0_09\bin"
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37958
    
  22
I said to delete the classpath, not the path. That path was wrongly set, anyway, because the reference to your Java installation should be first in the path. There is more about paths in this FAQ.

When I corrected the error I spotted earlier, and put all three of your classes into a file called Main.java, the code compiled and ran successfully. You should change println in the Piece class to print, however.
Try the following at a command line
echo %PATH%
echo %CLASSPATH%
java -version
javac -version
You should get nothing for %CLASSPATH%. A Windows® command line is case‑insensitive, so you can probably use %classpath% instead.
 
jQuery in Action, 2nd edition
 
subject: can not find symbol
 
Similar Threads
Compiling multiple source files.
Cannot find symbol error
Example for Certification book doesnt work
Private constructor inheritance
SCJP Brainteaser (1)