• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

bad class file error, compiling with packages

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

"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".
 
Karen Nelson
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
You are HERE! The other map is obviously wrong. Better confirm with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic