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

Javac cannot find the parent class

Kok Lum Chan
Greenhorn

Joined: Apr 12, 2009
Posts: 10
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.





[Thumbnail for hierachy.JPG]

marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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

Joined: Apr 12, 2009
Posts: 10
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
Sheriff

Joined: Sep 28, 2004
Posts: 18978
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Kok Lum Chan
Greenhorn

Joined: Apr 12, 2009
Posts: 10
Hi Henry,

That explains everything. Thank you.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javac cannot find the parent class