| Author |
need packages help
|
rajesh baba
Greenhorn
Joined: May 19, 2007
Posts: 25
|
|
why i am unable to import all classes in a user defined package .that is i had more than one class in mypakage i used import mypackage.*; but i am getting a complier error its working only if i specified my class name example :import mypackage.Employee; and i observed that in java package all files are in .java format not .class format why can any one explain
|
 |
Raghavan Muthu
Ranch Hand
Joined: Apr 20, 2006
Posts: 3327
|
|
No, you should not be getting an error when you import with a '*'. Can you give your classes and program importing them? Are you using an editor or an IDE (like eclipse, Netbeans etc)? If so you must have attached the jar file with source for all java files. Just check.
|
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
|
 |
rajesh baba
Greenhorn
Joined: May 19, 2007
Posts: 25
|
|
i had a package named food it contains two class files named 1)Car(abstract class) 2)Fruit class know i imported classes import food.*; class Ptest extends Car { public void Speed() { System.out.println("good speed"); } public void acc() { System.out.println("good acceleration"); } public static void main(String args[]) { Ptest p=new Ptest(); } } C:\j2sdk1.4.2_09\bin>javac Ptest.java Ptest.java:2: cannot access Car bad class file: .\Car.class class file contains wrong class: car Please remove or make sure it appears in the correct subdirectory of the classpa th. class Ptest extends Car ^ 1 error is i used this one as shown below import food.Car; class Ptest extends Car { public void Speed() { System.out.println("good speed"); } public void acc() { System.out.println("good acceleration"); } public static void main(String args[]) { Ptest p=new Ptest(); } } output C:\j2sdk1.4.2_09\bin>javac Ptest.java no error why this happens
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
It would be interesting to see the code in the Car.java file. Is the class name "Car" or "car"? [ May 25, 2007: Message edited by: Barry Gaunt ]
|
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
|
 |
rajesh baba
Greenhorn
Joined: May 19, 2007
Posts: 25
|
|
car.java code package food; public abstract class Car { public abstract void Speed(); public abstract void acc(); }
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
|
Try renaming the file name to Car.java instead of car.java.
|
 |
rajesh baba
Greenhorn
Joined: May 19, 2007
Posts: 25
|
|
|
its named as Car.java only it works only is i specify the class name but not if i use import food.*;
|
 |
krishna bulusu
Ranch Hand
Joined: Aug 28, 2006
Posts: 185
|
|
********************************* its named as Car.java only it works only is i specify the class name but not if i use import food.*; ********************************** I didn't get the above line!!! can any one explain that?
|
Thanks&Regards, Krishna.
SCJP1.4, SCWCD1.4, SCBCD 5.0
|
 |
Raghavan Muthu
Ranch Hand
Joined: Apr 20, 2006
Posts: 3327
|
|
Hi Krishna,
didn't get the above line!!! can any one explain that?
Please read his first post and thats where his question started off.
|
 |
rajesh baba
Greenhorn
Joined: May 19, 2007
Posts: 25
|
|
posted Today 1:06 PM Profile for krishna bulusu Send New Private Message Edit/Delete Post Reply With Quote ********************************* its named as Car.java only it works only is i specify the class name but not if i use import food.*; ********************************** I didn't get the above line!!! [banghead] can any one explain that? RE: see the code i posted then you will understand i mean in case 1 of my code i used "import food.*;"(it giving a complier error) in case 2of my code i used "import food.Car;"(it will not give any error ) thats what i mean
|
 |
Raghavan Muthu
Ranch Hand
Joined: Apr 20, 2006
Posts: 3327
|
|
Hi rajesh baba, Just check where you keep your Ptest class. I think it is also present inside the food package (in the OS perspective, "food" folder). In such case, you would get this error. Just keep the "Ptest.java" class outside of the "food" folder and then compile it. It will work!!
|
 |
Amarnath Revuri
Greenhorn
Joined: May 25, 2007
Posts: 1
|
|
Just have the Car.java in food folder and Ptest.java in out side folder. As you both classes are public make sure that your class name and filename are same. here is the example of your folder structure in your case. C:\myjava\Ptest.java C:\myjava\food\Car.java in C:\myjava folder execute javac Ptest.java -AR
|
 |
rajesh baba
Greenhorn
Joined: May 19, 2007
Posts: 25
|
|
Ptest.java file is in c:\j2sdk1.4.2_09\bin\ where as Car.class file is in c:\j2sdk1.4.2_09\bin\food\ this there any mistake here
|
 |
Raghavan Muthu
Ranch Hand
Joined: Apr 20, 2006
Posts: 3327
|
|
|
then absolutely there should NOT be any problem rajesh. It should work fine.
|
 |
rajesh baba
Greenhorn
Joined: May 19, 2007
Posts: 25
|
|
hi Raghavan Muthu really its not working dude you try it with same files i had i send you code also its really not working.i hope the prolem is with (.*)
|
 |
Nik Arora
Ranch Hand
Joined: Apr 26, 2007
Posts: 652
|
|
Hi Rajesh, This sounds interesting. Just check your classpath and compile. Regards Nik
|
 |
rajesh baba
Greenhorn
Joined: May 19, 2007
Posts: 25
|
|
i hope there is no problem with classpath beacuse the other statement (import food.Car is working. ----------------------------------------------------------------- And one more thing what a package should contain a .java file or .class file i hope its a .class file but why the standard java package consists of .java files can any one explain
|
 |
 |
|
|
subject: need packages help
|
|
|