aspose file tools*
The moose likes Beginning Java and the fly likes classpath problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "classpath problem" Watch "classpath problem" New topic
Author

classpath problem

Layla Rashid
Ranch Hand

Joined: Dec 25, 2006
Posts: 36
Hi
I am trying to run this Category.java file


my Store.java file is


when I try to compile I get this error.

C:\Program Files (x86)\Java\jdk1.5.0_20\bin>javac -cp C:\Users\silvi\workspace\s
hop\src\ca\acadiau\ecomm C:\Users\silvi\workspace\shop\src\ca\acadiau\ecomm\Cate
gory.java
C:\Users\silvi\workspace\shop\src\ca\acadiau\ecomm\Category.java:6: cannot find
symbol
symbol : class Store
location: class ca.acadiau.ecomm.Category
public Category (Store s, int n){
^
1 error


Please let me know how to solve this.

Thanks
Layla


Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Layla. First compile Store.java and then compile Category.java.
Layla Rashid
Ranch Hand

Joined: Dec 25, 2006
Posts: 36
I already did that .
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


I already did that .


So you still get error ?

you dont need to compile Store.java separately..it automatically compiles when you compile Category.java. use -classpath properly to get compiled.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Wouldn't it be easier to put the Java compiler on your path and work in your actual directory?!
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14352
    
  22


C:\Program Files (x86)\Java\jdk1.5.0_20\bin>javac -cp C:\Users\silvi\workspace\shop\src\ca\acadiau\ecomm C:\Users\silvi\workspace\shop\src\ca\acadiau\ecomm\Category.java
C:\Users\silvi\workspace\shop\src\ca\acadiau\ecomm\Category.java:6: cannot find symbol
symbol : class Store
location: class ca.acadiau.ecomm.Category
public Category (Store s, int n){
^
1 error

Multiple things are going wrong here...

Do not run this from the JDK bin directory. A command like this would write the resulting class files in your JDK bin directory, and that's not what you want. Follow step 4 of the JDK installation instructions to put the JDK bin directory in your PATH, so that you can call it from anywhere.

You have to set the classpath to the base directory of the package structure. So, don't set it to C:\Users\silvi\workspace\shop\src\ca\acadiau\ecomm, but to C:\Users\silvi\workspace\shop\src. If you compile with that directory as the current directory, you don't have to set the classpath at all.

After setting the PATH, do something like this:

C:
cd \Users\silvi\workspace\shop\src
javac ca\acadiau\ecomm\Category.java

You will now have a Category.class file in the same directory of your source file.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: classpath problem