• Post Reply Bookmark Topic Watch Topic
  • New Topic

I get an error when I compile [Bad class file]  RSS feed

 
Youtube gilman
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


SOURCE CODE



Player.java


Please help!
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THis has nothing to do with the code you've shown -- it has to do with precisely how you invoke the compiler, and how the Java files are arranged in folders on your disk.

I don't recognize the messages above, especially the "Please wait while we load up our compiler." What are you using to build this source code? And are these exact error messages cut and pasted from your command line, or did you retype them (which could possibly result in small changes which can be extremely important?)


 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




The path and import statement do not match the package declaration in the class file.
 
Keith Rainey
Ranch Hand
Posts: 66
Android Eclipse IDE IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where does Smelting.java live? ( with your package, it should be in src\com\rs2hd\content\skills\smithing\Smelting.java )


If it's there, what command are you issuing to compile it? What is the current directory when you issue the command?
 
Youtube gilman
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keith Rainey wrote:Where does Smelting.java live? ( with your package, it should be in src\com\rs2hd\content\skills\smithing\Smelting.java )


If it's there, what command are you issuing to compile it? What is the current directory when you issue the command?



 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error message sounds like you are using a Java source file in a place where you should have used a compiled *.class file.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:The error message sounds like you are using a Java source file in a place where you should have used a compiled *.class file.


No, like I said before: it is because his package statement and folder structure don't match. The package is declared as "com.rs2hd.content.skills.Smelting" which means it should be in
the path "src\com\rs2hd\content\skills\Smelting\Smelting.java." But it isn't, and the error message tells you this in two ways:
1) cannot access com.rs2hd.content.skills.smithing.Smelting - it can't access that because it does not exist. The fully qualified name of the class shown to us is "com.rs2hd.content.skills.Smelting.Smelting"
2) bad class file: src\com\rs2hd\content\skills\smithing\Smelting.java file does not contain class com.rs2hd.content.skills.smithing.Smelting - which is true, it contains "com.rs2hd.content.skills.Smelting.Smelting"

The error message then tells you what to do to fix the problem:
- Please remove or make sure it appears in the correct subdirectory of the classpath. - The .java file should be moved to the path "src\com\rs2hd\content\skills\Smelting\Smelting.java" and all the references to it
changed to "com.rs2hd.content.skills.Smelting.Smelting" OR (probably simpler) the package should be changed to "com.rs2hd.content.skills.smithing" and the file and references left in place.
 
Campbell Ritchie
Marshal
Posts: 56581
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don’t use tab characters for indenting, nor such long lines, which make your code very difficult to read.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!