aspose file tools*
The moose likes Applets and the fly likes bad class file error, compiling with packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "bad class file error, compiling with packages" Watch "bad class file error, compiling with packages" New topic
Author

bad class file error, compiling with packages

Karen Nelson
Ranch Hand

Joined: Aug 19, 2005
Posts: 57
Hi again,
In the continuing saga of trying to get these applets up... I am trying to follow the directions in Head First Java for compiling and running with packages.

So MyProject has two directories, source and classes. Each of these has a directory called com which has a directory called rephunk which has all the .java or .class files in it. So far so good. However, I also have a set of classes that I've developed that is used by all 6 applets (Graph, GraphPanel, etc). So I put these all into a directory called myclasses with a similar directory structure.

When I try to compile the applet, I use a classpath to indicate where the shared classes are, so I type "javac -d ..\classes -cp .;c:\java\myclasses\source\com\rephunk\*.java"

However, then I get the following error :

"cannot access GraphPanel.
bad class file: c:\java\myclasses\source\com\rephunk\GraphPanel.java
file does not contain class GraphPanel
Please remove or make sure it appears in the correct subdirectory of the classpath"

It doesn't complain about the other classes, and I can't find anything wrong with the GraphPanel.java file, which has always worked fine until now.

Thank you again for your help!
Karen.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41489
    
  53
"javac -d ..\classes -cp .;c:\java\myclasses\source\com\rephunk\*.java"

There are two problems here.
First, you include source files in the classpath. That will not work - they need to be class files.
Second, you specify the complete directory path, when you should be specifying the root of the class directory.
So it should probably read "-cp .;c:\java\myclasses\classes".


Ping & DNS - my free Android networking tools app
Karen Nelson
Ranch Hand

Joined: Aug 19, 2005
Posts: 57
I guess that's why its called a classpath, not a sourcepath! I'm embarrassed to say I never thought about it.

For the sake of completeness, I also found I had left the package statement out of one of the files (not the one being complained about, but still...)

Thank you again! Karen
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: bad class file error, compiling with packages