File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Javac cannot find the parent class

 
Kok Lum Chan
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I tried to put 2 files (parent and child) into 2 different packages (LearnJava.One & LearnJava.Two) as shown in the attached.

Parent - compiled success.



Child - compile with errors



The error i got is



I have updated that CLASSPATH to point to the location of the Parent.class but i still unable to figure out why i got the error.

Classpath = .;D:\LearnJava;D:\LearnJava\Two;D:\LearnJava\One;<some other paths>

Appreciate if anyone could assist to highlight my mistake(s).

Thanks.


hierachy.JPG
Files structure
[Thumbnail for hierachy.JPG]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
koklum chan wrote:...I have updated that CLASSPATH to point to the location of the Parent.class but i still unable to figure out why i got the error.

Classpath = .;D:\LearnJava;D:\LearnJava\Two;D:\LearnJava\One;<some other paths>...

Java is looking for the package, "LearnJava.One." The location of this is simply "D:\", which does not appear to be included in your classpath.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that you could also do this from the command prompt as follows...

D:\LearnJava\Two>javac -cp ../.. Child.java

In this case, your current directory is D:\LearnJava\Two, and you are specifying a classpath (-cp) that is two directories higher (../..), which puts you back at D.

OR you could simply use D as your current directory (which is where these packages reside, so the dot in your classpath should work), and then provide the relative path for compiling Child.java...

D:\>javac LearnJava/Two/Child.java
 
Kok Lum Chan
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marc,

Thank you for your guidance and your recommentation works.

marc weber wrote:
koklum chan wrote:...I have updated that CLASSPATH to point to the location of the Parent.class but i still unable to figure out why i got the error.

Classpath = .;D:\LearnJava;D:\LearnJava\Two;D:\LearnJava\One;<some other paths>...

Java is looking for the package, "LearnJava.One." The location of this is simply "D:\", which does not appear to be included in your classpath.


This is what i do not understand. Why Java cannot locate the parent.class when i am using absolute path (D:\LearnJava\One) in CLASSPATH but specifying D:\ works ?

Is it trying to locate the package (not covered in my classpath) then only the class in the package (covered in the classpath) ?


 
Henry Wong
author
Marshal
Pie
Posts: 20831
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
koklum chan wrote:

This is what i do not understand. Why Java cannot locate the parent.class when i am using absolute path (D:\LearnJava\One) in CLASSPATH but specifying D:\ works ?

Is it trying to locate the package (not covered in my classpath) then only the class in the package (covered in the classpath) ?




The classpath is used to specify the location of the root of the class files -- not the location of the class files. So if you specify the class path as D:\LearnJava\One and you specify the package as LearnJava.One, then it will look for the class file in D:\LearnJava\One\LearnJava\One\Parent.class.

Henry
 
Kok Lum Chan
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Henry,

That explains everything. Thank you.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic