• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

package

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 782
Python Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Michael. That worked!!
 
Michael Bruesch
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
When you have exhausted all possibilities, remember this: you haven't - Edison. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic