Java - java.lang.UnsupportedClassVersionError in applet
Asked Answered
N

2

5

I wrote not so simple app, and decided to make applet. I have the .jar archive and main class there is chat.java (it contains init() and extends JApplet). I have this code in HTML File:

<applet code="chat.class" archive="chat.jar" width="150" height="150">
Error!
</applet>

And it gives error

java.lang.UnsupportedClassVersionError: chat : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.defineClassHelper(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.access$100(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader$2.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.plugin2.applet.Plugin2ClassLoader.findClassHelper(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Exception: java.lang.UnsupportedClassVersionError: chat : Unsupported major.minor version 51.0

in Java console. I dont know what to do, my applet should open a new Frame (popup) where you can chat and so on. Thanx for any replies!

Nonfiction answered 19/1, 2012 at 18:49 Comment(2)
Can you verify that your java versions are the same where you compiled the jar?Hillier
"my applet should open a new Frame (popup) where you can chat and so on" Get rid of the applet completely and launch the frame from a link using Java Web Start. It is easier that deploying an applet, and a better experience for the user.Mccann
I
11

You have incompatible version of the class file and the java plugin. For example you compile your code in java7 and trying to run in on java5 or java6.

The Unsupported major.minor version 51.0 means that you have compiled your code in JDK7, and your browser plugin i JRE 6 or older and does not understand it.

In such situation you need to do one of:

  • update your java plugin (or switch to proper version if you have more), or
  • compile your applet for the older java using '-target' option.

To check your java version go to plugin test page.

Inge answered 19/1, 2012 at 18:52 Comment(2)
I have both newest versions. I dont know what to do... Im using eclipse, how to change target version?Nonfiction
@kittyPL: you can change in in your project properties->"Java Compiler"->"Compiler compliance level".Bastille
C
1

That exception means that you compiled your classes under a specific JDK, but then try to run them under older version of JDK. So, you can't run classes compiled with JDK 6.0 under JDK 5.0. Check your browser JRE version. Also you can specify a target JDK when compiling your classes.

Cohbert answered 19/1, 2012 at 18:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.