My program consists of classes that extend other classes. The problem is, when I try to compile them in cmd, system says “Cannot find symbol”. Some sites discussing similar problems mention including the source folder in the CLASSPATH. I did as they said and it still gives the same error. However, it runs smoothly in Eclipse. Any ideas why?
Share
Make sure that you compile the top level class first. If you try to compile a class extending other class, and you don’t have compiled
.classfile for that class, you will get that error.For the above code, you should compile the
.javafile containing yourclass Afirst to get your.javafile containingclass Bcompiled. Also, set the path containing yourclass filesin your classpath.In Eclipse, it works because it automatically compiles your classes as you save them.
NOTE: –
If you are having your classes under some packages, then compile your java files using this command: –
javac -d . A.java. This will create a folder for the package name and put the class file in that folder automatically. Then your class B would be able to find it