aspose file tools*
The moose likes Beginning Java and the fly likes package problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "package problem" Watch "package problem" New topic
Author

package problem

Nancy Lee
Greenhorn

Joined: Mar 23, 2002
Posts: 15
Hi there:
I have downloaded two files with the same package-name as their first statement from internet.
Their file structures are as follow:
1. for A.java :
package lvevl1.level2.level3;
some import statements;
public class A { some statements; }
2. for B.java:
package level1.level2.level3;
some import statements;
public class B extends A { some statements;}
I created a directory path :
c:\level1\level2\level3\ in my Window 98 driver c
then stored the two downloaded files there.
It is OK to compile A.java and create A.class. But when I tried to compile B.java, I got an error message : SuperClass Level1.Level2.Level3.A of class Level1.Level2.Level3.B not found.
This is my first time using package. Can anyone tell me what's wrong? Thanks.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
When you compile the class B you need to specify where class A is located in the classpath. For instance, if you are in c:\level1\level2\level3 you compile class A
> javac A.java
And then to compile class B you need to enter the following:
> javac -classpath ..\..\..;%CLASSPATH% B.java
And everything should be fine.
The "..\..\.." refers to C:. So in B there should be an import statement for A like
import level1.level2.level3.A;
To find A, the compiler must have a clue where to find level1 first (which is C: )
[ March 29, 2002: Message edited by: Valentin Crettaz ]

SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Nancy Lee
Greenhorn

Joined: Mar 23, 2002
Posts: 15
Thanks. It works now.
 
jQuery in Action, 2nd edition
 
subject: package problem