permaculture playing cards*
The moose likes Beginning Java and the fly likes package problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "package problem" Watch "package problem" New topic
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: 4968
    
    1

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
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: 4968
    
    1

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: 18546
    
  40

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: package problem
 
Similar Threads
inheritance problem?
What name to use to save files; what classes are allowed?
I Can't reference a class that's in the same package
regarding accessibility
an unbelievable question about import!!!