• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

package problem

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Nancy Lee
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. It works now.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic