Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can not find symbol

 
uzair ahmed
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 98
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this is a full copy of your source code, how does your main class (class 1) know about the Bishop class?
 
uzair ahmed
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am using
javac Main.java
to compile
 
Campbell Ritchie
Sheriff
Pie
Posts: 48972
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48972
60
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48972
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic