Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help on Packages!!

 
Swati Samudra
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....!
Swati
 
Ravindra Mohan
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sometimes helps to think of packages as if they were subdirectories, that way you get an idea of the likely visibility.
Marcus
 
Jane Griscti
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Swati,
Assuming you have the following setup:

and A.java is defined with:

and B.java 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 'B.java' 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic