0

I'm developing a Java applet that show a message box when you visit the site. This is my Java code:

import java.applet.Applet;
import javax.swing.JOptionPane;
public class JavaRun extends Applet {
    private static final long serialVersionUID = 1L; 
    public void init()
    { 
        JOptionPane.showMessageDialog(null, "hello world!");     
    }
}

This is the html:

<applet width='100' height='100' code='JavaRun' archive='data.jar'>
</applet>

On my computer (that have the java SDK) it's work, but when I'm using it on my laptop that have only the standard Java, I get these errors:

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: Micro : Unsupported major.minor version 51.0...
enter code here
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Don't use a mixture of Swing and AWT components, and don't use AWT components in this millennium. Change `extends Applet` to `extends JApplet`. – Andrew Thompson Mar 03 '12 at 13:39

3 Answers3

5

I believe You have different versions of Java environments on your computers. Run this command on both computers

java -version

And compare version numbers. Probably should run

javac -version

on Your development machine. If you get different version numbers update Java runtime environment on your laptop.

Martin
  • 2,135
  • 8
  • 39
  • 42
  • Thank you! in my development machine it 1.7 and in my laptop is 1.6 now how do change this on my development machine? –  Mar 03 '12 at 13:21
  • Check Mat's answer about -target flag. In short you have to specify in your project settings the target JVM version. Like this: `javac -target 1.6 -source 1.6 MyApplet.java` – Martin Mar 03 '12 at 13:27
  • If you use Eclipse check this SO question: [Where do you configure Eclipse Java compiler (javac) flags?](http://stackoverflow.com/questions/9483315/where-do-you-configure-eclipse-java-compiler-javac-flags) – Martin Mar 03 '12 at 13:34
4

UnsupportedClassVersionError: Micro : Unsupported major.minor version 51.0

This is the problem. You've compiled your applet with a class version that is not supported by the JVM you're running on the other system.

Use the -target flags for javac to produce class files for a given target JVM version.

Mat
  • 202,337
  • 40
  • 393
  • 406
3
UnsupportedClassVersionError
  • To compile code for a particular Java version, use the cross-compilation options. To do this properly will require an rt.jar of the target version (to use the bootclasspath option of javac).
  • To deploy code that requires a particular version, use deployJava.js
  • To maintain your sanity and provide a better user experience, convert the applet to an application and launch it from a link using Java Web Start.
Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433