7
java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:676)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:317)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:280)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at com.exe4j.runtime.LauncherEngine.launch(Unknown Source)
at com.install4j.runtime.MacLauncher.main(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at apple.launcher.LaunchRunner.run(LaunchRunner.java:115)
at apple.launcher.LaunchRunner.callMain(LaunchRunner.java:50)
at apple.launcher.JavaApplicationLauncher.launch(JavaApplicationLauncher.java:52)

I don't understand this at all; can anyone explain it simply? Thanks

Hendrik Brummermann
  • 8,242
  • 3
  • 31
  • 55
Peter
  • 71
  • 1
  • 2
  • 3
    Retagged from javascript to java. – Rob Raisch May 19 '11 at 23:53
  • 2
    @Rob, you could have fixed the code formatting, title, and remove txtisms while you were there. :) – sarnold May 19 '11 at 23:55
  • It means something broke. Perhaps with more code of what you're trying to do someone could explain what happened. – thedaian May 19 '11 at 23:56
  • possible duplicate of [Java error: Bad version number in .class file error when trying to run Cassandra on OS X](http://stackoverflow.com/questions/1611312/java-error-bad-version-number-in-class-file-error-when-trying-to-run-cassandra) – sarnold May 19 '11 at 23:57
  • 1
    How are you compiling and running? See also [`UnsupportedClassVersionError `](http://download.oracle.com/javase/6/docs/api/java/lang/UnsupportedClassVersionError.html). – trashgod May 19 '11 at 23:59
  • http://javarevisited.blogspot.com/2011/07/javalangunsupportedclassversionerror.html is nice post on the issue. – alexsmail Jan 20 '12 at 00:21

5 Answers5

12

This error can occur when you compile the code with a newer version of the JDK and try to run it on an older version of the JVM. Is this your own code you're compiling and are you using an IDE (like Eclipse)? Try updating your JRE.

keyboardP
  • 68,824
  • 13
  • 156
  • 205
  • 1
    use java -version and javac -version to compare the version of your compiler vs the version of the JVM. – Vincent Ramdhanie May 19 '11 at 23:57
  • 3
    @Kevin This is actually a mistake that many beginners make when they start learning Java. Since we all were there once we should be tolerant of the mistakes that are made by the beginners. – Vincent Ramdhanie May 19 '11 at 23:58
  • How would i go about updating my JRE? – Peter May 20 '11 at 00:10
  • I don't use mac so I can't help you. But you might want to go to superuser.com or apple.stackexchange.com and ask there how to upgrade your JVM. – DJ. May 20 '11 at 00:18
  • @Peter - Do what Vincent suggested and type in `java -version` in your command prompt (assuming that your Java environment variables are installed). It'll tell you what version you have. You can download the latest version in the link in my answer. – keyboardP May 20 '11 at 00:24
  • This is what happened in the commnand prompt java version "1.5.0_28" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_28-b04-382-9M3326) Java HotSpot(TM) Client VM (build 1.5.0_28-157, mixed mode, sharing) – Peter May 20 '11 at 00:41
  • Current version is 1.6 so it's quite possible that your code has been compiled with 1.6 instead of 1.5 (your current JRE version). You can either target 1.5 with your code, or you can download the latest JRE from the link in my answer. – keyboardP May 20 '11 at 00:44
  • For just the `JRE`, go here: http://www.oracle.com/technetwork/java/javase/downloads/jre-6u25-download-346243.html and select your operating system. – keyboardP May 20 '11 at 00:47
  • Oh sorry, I missed you using Mac. I'm not familiar with Macs. Google comes up with various results, or you go directly to Apple's site. This post might help as well: http://stackoverflow.com/questions/1577014/how-install-a-specific-jdk-on-mac-os-x – keyboardP May 20 '11 at 00:58
  • i updated to 1.6.2.04 or whatever and it still doesnt work any other ideas? – Peter May 20 '11 at 01:44
  • What version do you get when you type `javac -version` (notice the `c` at the end of java) – keyboardP May 20 '11 at 02:05
  • Java version "1.6.0_24" Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-9M3326) Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode) – Peter May 20 '11 at 02:29
  • I'm not familiar with macs, so maybe someone else has experience with Mac and Java. What you could try is targetting your code to compile to a different version number. How you do this depends on what IDE you're using. – keyboardP May 20 '11 at 02:34
  • whats an IDE and how would i go about finding which one im using?? – Peter May 20 '11 at 02:36
  • IDE is an Integrated Development Environment. `Eclipse` is an example of an IDE (google it). How did you compile the code? Did you use something like `Eclipse` or straight command prompt? – keyboardP May 20 '11 at 02:50
1

It means that your compiler was producing something targeted at a higher Java version than the JVM you are attempting to run it on.

eg compiled for java 6 and running with java 5.

Solution 1: upgrade the jvm (type java -version to see what you have)

Solution 2: target a lower version (in eclipse java compiler settings, for example)

cidermonkey
  • 306
  • 1
  • 8
1

JAVA_HOME should be defined with the java version that younger ot the same that you used for compilation.

Raman
  • 887
  • 4
  • 12
  • 28
0

I was getting this error when I installed JRE 1.8 and tried to run Hello World of GAE application on Eclipse Kepler. This is solution:

I installed Java 8 support for Kepler from Eclipse Marketplace. Then I resolved my problem by going to Eclipse -> Right click on project file -> Properties -> Java Build Path, I removed JRE System Library 1.6, clicked Add Library -> JRE System Library -> Installed JRE's. Then I clicked Search, it automatically found version 1.8 and then I returned to previous view, selected 1.8 and now everything works fine!

Denis Kutlubaev
  • 15,320
  • 6
  • 84
  • 70
0

It is saying you are using class file for different version of java runtime. What program are you installing (I notice installj in your stacktrace)?

Try upgrading your Java runtime.

DJ.
  • 6,664
  • 1
  • 33
  • 48
  • Im trying to install a program called marvin sketch for my orgo lab, i thought i had to change my java so i did but now i dont know how to fix it – Peter May 20 '11 at 00:06
  • What did you mean by changing your java? Did you do something to your java prior to running the installation program? – DJ. May 20 '11 at 00:07
  • 1
    Yea, i went here http://www.oracle.com/technetwork/java/javase/downloads/index.html and download one of the programs but i dont know which one im so confused:( – Peter May 20 '11 at 00:11