aspose file tools*
The moose likes Beginning Java and the fly likes Problem with packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with packages" Watch "Problem with packages" New topic
Author

Problem with packages

Angela lewis
Ranch Hand

Joined: Mar 01, 2004
Posts: 100
I have created a directory in my C drive with the name food.
In this directory I have made a class called Fruit.java such as

package food;
public abstract class Fruit
{
public abstract void methodFruit();
}

I compiled it using
c:\food>javac Fruit.java

Then i made a class in C drive with default package such as

import food.Fruit;
class Apple extends Fruit
{
public static void main(String[] args)
{
System.out.println("Apple");
}
public void methodFruit()
{
System.out.println("Fruit");

}
}

When i try to compile this file using

c:\>javac Apple.java

I get the following error

Apple.java:1: package food does not exist
import food.Fruit;
^
Apple.java:2: cannot access Fruit
bad class file: c:\food\Fruit.class
class file contains wrong class: food.Fruit
Please remove or make sure it appears in the correct subdirectory of the classpath.
class Apple extends Fruit
^

I have set the classpath as
set classpath=c:\food;
How should I correct this problem.
Takumi Fujiwara
Greenhorn

Joined: Nov 17, 2003
Posts: 6
I'm fairly new at java, but why did you make a package food and try to import it? Polymorphism does not require that.
Angela lewis
Ranch Hand

Joined: Mar 01, 2004
Posts: 100
Then how else can i extend the Fruit class which is in the food package?
Mani Ram
Ranch Hand

Joined: Mar 11, 2002
Posts: 1140
Make sure that you have a dot (.) in the CLASSPATH. The dot denotes the current working directory
Modify your classpath to include the dot, using the following command, and try again.

SET CLASSPATH=.;%CLASSPATH%


Mani
Quaerendo Invenietis
Angela lewis
Ranch Hand

Joined: Mar 01, 2004
Posts: 100
Thanks a lot.
Classpath was the problem
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with packages