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

package

 
Toru Saito
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your classes need to be in directory "pac" and this directory
needs to be in your classpath.
Pho
 
Toru Saito
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Toru Saito
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael. That worked!!
 
Michael Bruesch
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic