i have an abstract class AbsCls.java and i compiled it: javac AbsCls.java so the class file is saved in the current working directory... but when i extended it : public class Derived1 extends AbsCls and compiled as: javac Derived1.java the class file should be at the same directory as that of the AbsCls.class... however i get error: unknown class AbsCls... this is not supposed to happen right? there is no need to declare package in both classes and to import AbsCls because its in the same package( current working directory)... i think in jdk1.2 this is ok but i'm using 1.4 now and i got this error... [ December 17, 2002: Message edited by: Benjoe Reyes ]
I tried reproducing your problem and I was able to compile my classes. You may want to check for typo and if the .class file itself is present in the working directory. You could trying posting your exact code so we could compile it ourselves. Hope that makes sense.
Check wether the "current directory" (".") is in your classpath.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Sometimes you may have to set your class path. If you class path is not set right the JVM may not be able to locate the other files. (Well this is the case if you have written both your classes in different files.)
Joined: Nov 05, 2002
your class path will have to be something like this: set classpath=(the path to get to the java library files);(the path to get to the directory where you have placed all your files); Eg: set classpath=c:\jdk1.4.1\lib;c:\javafiles; This might look a bit too juvenile,But it may help you.
Even if you do not feel the need, it is a good habit to explicitely declare classes in named packages. It does not cost a lot and I have seen so many errors due to the use of the anonymous package. W.
Joined: Apr 24, 2002
i got it... the classpath was cancelled out when i set the classpath to JavaRanchCommon because i'm also doing the cattle drive exercises i think i'll do what Divya Venkatesh said... set classpath for both however i put my files in different folders... is it better if i take out the set classpath to the JavaRanchCommon and set it as needed???
Whatever you prefer is what's better. If you think life is a bit easier to just have everything that is frequently used in your CLASSPATH setting, then do that. If such a configuration makes you feel sloppy and inefficient, then just specify class locations as they are needed. I've included the JavaRanchCommon package and other frequently used packages (such as junit.jar and j2ee.jar) in my system's CLASSPATH setting as I prefer to be a bit lazy about not wanting to frequently adjust the CLASSPATH.
set CLASSPATH=.;%CLASSPATH% means prefix the original value of CLASSPATH with a dot and a semicolon and assign the result to CLASSPATH. Suppose you have echo %CLASSPATH% printing C:\javaranch\lib\JavaRanchCommon.zip Then after doing set CLASSPATH=.;%CLASSPATH% echo %CLASSPATH% will print .;C:\javaranch\lib\JavaRanchCommon.zip That means two places will be searched: The first will be your current working directory (the one you cd into) represented by the dot and the second will be the JavaRanchCommon.zip file. -Barry