• Post Reply Bookmark Topic Watch Topic
  • New Topic

Bad Version Number in .class file  RSS feed

Jim Shaw
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just purchased "Head First Java" (2nd ed.), and am trying to do the first exercise after having downloaded the SDK.

I wanted the Java 2 Standard Edition SDK, as specified in the book, but I couldn't find that on the java.sun website (after all, the book was published in 2005) so I got Enterprise Edition 5 SDK instead.

I successfully compiled my first primitive program, which just spits out some text. Unfortunately, when I executed the program I got the following error:
"Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file at ...."

Here is my source code:
import java.awt.*;
import java.awt.event.*;
class Party {
public void buildInvite() {
Frame f = new Frame();
Label l = new Label("Party at Tim's");
Button b = new Button("You Bet");
Button c = new Button("Shoot me");
Panel p = new Panel();
} // more code here...

What direction can you give me to correct this error?

[ January 25, 2008: Message edited by: Jim Shaw ]
marc weber
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

Standard Edition (SE) is basic, "core" Java, and that's what you want for starting out. Enterprise Edition (EE) is an advanced edition for things like server programming.

Sun has some confusing approaches to naming and numbering. The language has been called "Java 2" since version 1.2 came out. Subsequent versions (1.3 through 1.6) are all considered "Java 2." To confuse things further, Java SE 6 is the same as Java SE 1.6, and this is the current version of the Java 2 Platform.

From Sun's Java SE download page, you can use JDK 6 Update 4, which is the current version of the "Java 2 Standard Edition SDK." This should work fine with the 2nd edition of Head First Java. After downloading, be sure to follow the installation instructions (especially the step about updating the PATH variable).

"Bad version number in .class file" usually means that the class was compiled using a Java Development Kit (JDK) that's newer than the Java Runtime Environment (JRE) trying to run it. Once you've installed JDK 6 (which includes the JRE), I think you'll be okay.

NOTE: The code you're working with is not complete. If you take another look at the book, you should see a note that explains the code is just a snippet to illustrate an overall concept, and it's not meant to be run as written. The "real" coding starts in the next few pages.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!