File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "package" Watch "package" New topic
Author

package

Toru Saito
Greenhorn

Joined: Oct 11, 2001
Posts: 4
I made two java files in the same directory.
// Pac.java - first file
package pac;
public class Pac{
}
// SPac.java - second file
package pac;
public class SPac{
Pac p;
}
When I compiled SPac.java, the compiler complained that it couldn't understand the symbol Pac.
Then I deleted package statement from both of them and that time Spac.java was compiled fine.
Why is that?
Please give me some help.
Thanks in advance.
Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

Your classes need to be in directory "pac" and this directory
needs to be in your classpath.
Pho


Regards,

Pho
Toru Saito
Greenhorn

Joined: Oct 11, 2001
Posts: 4
Thank for reply, Pho.
I put those two files in c:\java\programming\pac directory and set CLASSPATH in autoexec.bat:
SET CLASSPATH=.;c:\java\programming\pac;
(By the way my os is Win95)
Then I rebooted the computer and tried to compile it again.
But it didn't work.
Is there something wrong with the way to set CLASSPATH or what?
Michael Bruesch
Ranch Hand

Joined: Sep 23, 2001
Posts: 158
Leave off the actual folder where your package begins, just direct the classpath to the directory where your packages are stored like so:
SET CLASSPATH=.;c:\java\programming
I'm no classpath expert, but I had this very problem not 2 days ago, and this worked for me.

------------------
Michael J Bruesch
Codito, ergo sum...
I code, therefore I am.
My Java Games, I'm quite proud


Michael J Bruesch<br /><i>I code, therefore I am.</i>
Toru Saito
Greenhorn

Joined: Oct 11, 2001
Posts: 4
Thanks Michael. That worked!!
Michael Bruesch
Ranch Hand

Joined: Sep 23, 2001
Posts: 158
As far as I'm concerned, that's the best way to learn, mess up, then try again and get it right. That's how I always do it! (Although it may not be the easiest way).

------------------
Michael J Bruesch
Codito, ergo sum...
I code, therefore I am.
My Java Games, I'm quite proud
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: package
 
Similar Threads
Members Scope
package
nested Packages
Compile error Package Does not Exit
basic Q.