• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

need packages help

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
rajesh baba
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
rajesh baba
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
car.java code
package food;
public abstract class Car
{
public abstract void Speed();
public abstract void acc();
}
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try renaming the file name to Car.java instead of car.java.
 
rajesh baba
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
its named as Car.java only it works only is i specify the class name but not if i use import food.*;
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
*********************************
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?
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
then absolutely there should NOT be any problem rajesh. It should work fine.
 
rajesh baba
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 (.*)
 
Ranch Hand
Posts: 652
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rajesh,
This sounds interesting. Just check your classpath and compile.



Regards
Nik
 
rajesh baba
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic