| Author |
Importing java files in another java program
|
smyle khanna
Ranch Hand
Joined: Jan 14, 2004
Posts: 54
|
|
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 ]
|
 |
jamma jacob
Greenhorn
Joined: Mar 22, 2004
Posts: 12
|
|
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
|
SCJP 1.2
|
 |
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
|
|
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 ;-)
|
Java API Documentation
The Java Tutorial
|
 |
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
|
|
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!
|
[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
|
 |
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
|
|
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 packagePackage creationdisturbing package issueUnable to compile a package
|
 |
smyle khanna
Ranch Hand
Joined: Jan 14, 2004
Posts: 54
|
|
Hi DIRK.. Thanks a lot..my program is running fine without creating any packages ... smyle
|
 |
 |
|
|
subject: Importing java files in another java program
|
|
|