| Author |
package problem
|
jittu goud
Ranch Hand
Joined: Mar 30, 2007
Posts: 46
|
|
hi all i have a little problem in referenceing packages
I have the following classes
First class
second class
...
when i compile first class...it compiles fine..
but when i compile the second class...it cannot find the package one.
both my classes are in same directory...and i have included the directory in PATH variable...and iam using vista ...
|
 |
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Joined: Aug 26, 2006
Posts: 4967
|
|
both my classes are in same directory
Shouldn't the two classes be in separate directories? One package class in the one directory, and the two package class in the two directory.
Remember, the term package is just a Javaesque name for a folder. If two classes are in two different packages, that means they are in two different folders, with the folders nested in the same manner that the package is delineated with periods or 'dots.'
-Cameron McKenzie
|
Author of Hibernate Made Easy, What is WebSphere???, JSF 2.0 Made Easy and the SCJA Certification Guides
|
 |
jittu goud
Ranch Hand
Joined: Mar 30, 2007
Posts: 46
|
|
thanks a lot for the early reply...
ok....as you suggested i just created a folder called java -- and two sub direcories one and two
folder Desktop/java/one --- contains A.java
folder Desktop/java/two --- contains B.java
now i compile A compiles fine...
and B throws the same error...and says package one does not exists....
|
 |
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Joined: Aug 26, 2006
Posts: 4967
|
|
With everything in the proper folder, the only message you should get is:
"The Field a.p is not visible."
The following code will compile properly:
|
 |
Balu Sadhasivam
Ranch Hand
Joined: Jan 01, 2009
Posts: 874
|
|
Jittu,
Compile with Desktop/java/ (complete folder name) in classpath
javac -cp "Desktop/java/";. B.java
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16687
|
|
now i compile A compiles fine...
and B throws the same error...and says package one does not exists....
The other thing to keep in mind is that the classpath specifies the root of the classes -- and if you don't specify a classpath, it assumes the current directory is the root. So... you need to compile from the root directory...
> cd Desktop/java
Desktop/java> javac one/A.java
Desktop/java> javac two/B.java
[And by root directory, I mean the root of the java classes -- not the unix root directory]
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
jittu goud
Ranch Hand
Joined: Mar 30, 2007
Posts: 46
|
|
Thanks a Lot friends...it compiles.....from root directory
|
 |
 |
|
|
subject: package problem
|
|
|