Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - java.lang.UnsupportedClassVersionError in applet

Tags:

java

applet

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!

like image 665
noisy cat Avatar asked Jan 19 '12 18:01

noisy cat


2 Answers

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.

like image 121
Michał Šrajer Avatar answered Oct 13 '22 22:10

Michał Šrajer


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.

like image 26
Mike K. Avatar answered Oct 13 '22 21:10

Mike K.