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

package problem

 
jittu goud
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jittu,

Compile with Desktop/java/ (complete folder name) in classpath

javac -cp "Desktop/java/";. B.java
 
Henry Wong
author
Marshal
Pie
Posts: 21117
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
jittu goud
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a Lot friends...it compiles.....from root directory
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic