File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Help on Packages!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Help on Packages!!" Watch "Help on Packages!!" New topic

Help on Packages!!

Swati Samudra

Joined: Dec 27, 2000
Posts: 16
I have class A in Package P1 and its sub-class Class B in Package P2. I am able to compile class A from P1 directory on the prompt but I am Getting erro when I compile Class B from P2 directory at the prompt. I have import statement in class B importing class A and the error message says can't find class A and gives error at import statement.
How can I compile class B in package P2?
am confused....!
Ravindra Mohan
Ranch Hand

Joined: Mar 16, 2001
Posts: 216
Hi Swati,
Just check whether your import statement is import p1.*; or not. If you want to import only the class A from the package P1 then your import statement should be import P1.A ;.
Also, please check , are you trying to access the members of
class A through a reference of A class or reference of class B. Finally, do make it point to check the access modifier of the
class A in package P1.
Please revert in case this is still a problem. You may post your code so that we can figure out the exact problem.
Ravindra Mohan.

[This message has been edited by Ravindra Mohan (edited May 24, 2001).]
Marcus Green
arch rival

Joined: Sep 14, 1999
Posts: 2813
It sometimes helps to think of packages as if they were subdirectories, that way you get an idea of the likely visibility.

SCWCD: Online Course, 50,000+ words and 200+ questions
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Swati,
Assuming you have the following setup:

and is defined with:

and is defined with:

use the following commands to compile from the c:\someDir prompt:

Java assumes the package names follow the directory structure. If you try to compile '' from within the 'P2' directory it expects to find the 'P1' directory referred to in the 'import' statement within the current directory.
Hope that helps.
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform

Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
I agree. Here's the link:
subject: Help on Packages!!
It's not a secret anymore!