Java Applet work only on my computer?

狂风中的少年 提交于 2019-12-13 05:13:51

问题


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

回答1:


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.




回答2:


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.




回答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.


来源:https://stackoverflow.com/questions/9546359/java-applet-work-only-on-my-computer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!