Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / February 2004

Tip: Looking for answers? Try searching our database.

working with packages

Thread view: 
Luc Van Bogaert - 29 Feb 2004 19:38 GMT
Hi,

I'm trying to organize my classes in packages, but I'm running into a
problem where I can't seem to reference a class which is higher or at
the same level of the package hierarchy. I can only reference a class
when it is lower in the hierarchy.

example :

dir             collector    data

class MainPanel                class Album

I can reference Album from MainPanel, but not vice versa.
Any idea how to do this?

Thanks.

Signature

Luc Van Bogaert

Jean-Philippe Martin - 29 Feb 2004 19:46 GMT
Hi,

I've got a problem to understand your exemple but I will try to help with
what I understood :o)

With a class in the same package, you don't have to import anything.
With a class that is higher, it's maybe a problem of visibility. Try to give
the visibility "protected" to your higher class.

I hope it will help.

Jean-Philippe.
Luc Van Bogaert - 29 Feb 2004 20:27 GMT
> Hi,
>
[quoted text clipped - 6 lines]
>
> I hope it will help.

I will try to explain :

I have two classes in the same package directory (collector/data) within
my project.

    package collector.data;
    public abstract class Record {
    }

    package collector.data;
    public class Album extends Record {
    }

The compiler displays an error message saying Record.class can't be
found. These classes are in the same directory, and both declared public.

Thanks.
Signature

Luc Van Bogaert

Jean-Philippe Martin - 29 Feb 2004 20:55 GMT
> package collector.data;
> public abstract class Record {
[quoted text clipped - 6 lines]
> The compiler displays an error message saying Record.class can't be
> found. These classes are in the same directory, and both declared public.

Here is the same code:

I place 2 classes in the same directory as yours.

package collector.data;
public abstract class Record {

   public abstract void printHello();

}

and

package collector.data;

public class Album extends Record {

   public static void main(String argv[]){

       Album myAlbum = new Album();

       myAlbum.printHello();

   }

   public void printHello() {

       System.out.println("Hello.");

   }

}

With these import I don't have any error. What kind of IDE do  you use ? I
suggest you to use Eclipse (eclipse.org) it prevents you of a lot of errors
;o)
Luc Van Bogaert - 29 Feb 2004 23:40 GMT
> With these import I don't have any error. What kind of IDE do  you use ? I
> suggest you to use Eclipse (eclipse.org) it prevents you of a lot of errors

I don't use an IDE, just a programmers editor, and I compile from my
file manager app. I have found the problem already : I have to start
javac.exe from my main project dir instead of one of the package
subdirectories, or otherwise specify the classpath to include the
required paths for my project.

Thanks for your help.

Signature

Luc Van Bogaert



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.