Re: Java package problem
dkra wrote:
x-no-archive: yes
In article <tKdCg.35030$k54.6989@newsfe11.phx>, Knute Johnson
<nospam@rabbitbrush.frazmtn.com> wrote:
<snip>
You have to be in the directory above your package to run a program in
the package.
Yes, I understand that.
But what I failed to do was even compile the file contained in the package
(I was in the package directory).
The only change I made in this file was by declaring some part of it (the
Book class) "public" (class, constructor, methods) which had previously
been "private."
In other words,
(2) runs OK here
^
|
BookPack |
__________ |
| |
_________ BookDemo.java (private) <--- (1) compiles OK here
BUT,
(2) can't compile in BookPack, so can't even run here
^
|
BookPack |
__________ |
| |
_________ BookDemo.java (public) <--- (1) can't compile here
Why does this not work now?
-- dkra
That isn't all you changed. You created another file called UseBook.java, and
it's that which will not compile. You show no indication that BookDemo.java
will not compile.
You have two java source files in the same directory which belong to different
packages. This will not work - each package requires its own directory, and
classes belonging to that package must be in that directory. The two packages
are BookPack, with class BookDemo, and BookPackB with class UseBook. Your
directory structure should look like this:
Base directory
/ / BookPack BookPackB
| |
BookDemo.java UseBook.java
BookDemo.class UseBook.class
Your classes are then referenced as BookPack.BookDemo and BookPackB.UseBook.
--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555