• 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

Importing java files in another java program

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi...
I have 2 java programs in which one inherits the other.i used the import statement to inherit the other file in the other..but its givin errors..
i tried creating packages and also tried but all in vain...
the object of the first class declared is not accepted in the second one.
it gives the following errorS:

the code of 2 programs r given below


plz help me out......
[ edited to break long lines, disable smilies, and to remove the evil tab character -ds ]
[ April 12, 2004: Message edited by: Dirk Schreckmann ]
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hI
sMYLE
Put both in the same directory without package and compile.Find Out
Whether it works and what is this 'import pool.*' Is connectionPool in it
If it is where is the package name in connectionpool

Check it out
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have found it tricky to get my own packages and imports to work correctly. I strongly suggest you follow the suggestion made by "red bull" and put all your java files in one directory and not worry about import statements. Get it to compile that way before you start organizing your packages.
When you get that much to work, make sure each java file has a line such as:
package pool;
This will define the package that should contain the classes in that file. Also, these files should all be in a subdirectory (or folder) named "pool".
Finally, you will need to add the folder that contains this pool folder to your CLASSPATH. If you put your source files in a directory called C:\my_java_files\pool, then you need to add C:\my_java_files to the CLASSPATH variable in order to allow import statements to find the appropriate package and its classes.
HTH
Layne
p.s. Someone, please correct me if I've made any mistakes above.
p.p.s. RED BULL: you should change your name to follow the naming policy before a Sheriff arrests you ;-)
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
red bull,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
smyle khanna,
Your code almost compiles.
If you remove the import pool.*; statement, then you'll discover that your only remaining problem concerns not handling the thrown exceptions of the ConnectionPool constructor in your subclass constructor.
To fix that, you could just add a no argument constructor to your subclass that throws the same exceptions.
Now, for help on figuring out the whole "how to get my packages and imports to work thing", let me recommend reading a few past conversations on the subject, which include some step-by-step instructions.
  • jvm can't find class in same package
  • Package creation
  • disturbing package issue
  • Unable to compile a package
  •  
    smyle khanna
    Ranch Hand
    Posts: 54
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi DIRK..
    Thanks a lot..my program is running fine without creating any packages ...
    smyle
     
    reply
      Bookmark Topic Watch Topic
    • New Topic