• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help on Packages!!

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic