• 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

Composition

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check wether the "current directory" (".") is in your classpath.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.)
 
Divya Venkatesh
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Benjoe Reyes
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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???
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Benjoe Reyes
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ilja Preuss:
Check wether the "current directory" (".") is in your classpath.


what does this one means???
set classpath = "."%classpath% ???
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Benjoe Reyes
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so set CLASSPATH=C:\javaranch\lib\JavaRanchCommon.zip;.;%CLASSPATH% will do the trick...
because setting them up separately will cancell the previous one, right???
thanks Barry...
 
reply
    Bookmark Topic Watch Topic
  • New Topic