简体   繁体   English

Java Applet仅在我的计算机上工作吗?

[英]Java Applet work only on my computer?

I'm developing a Java applet that show a message box when you visit the site. 我正在开发一个Java小程序,当您访问该站点时会显示一个消息框。 This is my Java code: 这是我的Java代码:

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: 这是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: 在我的计算机上(具有Java SDK)可以正常工作,但是当我在仅具有标准Java的笔记本电脑上使用它时,出现以下错误:

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

I believe You have different versions of Java environments on your computers. 我相信您的计算机上具有不同版本的Java环境。 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. 如果获得不同的版本号,请在笔记本电脑上更新Java运行时环境。

UnsupportedClassVersionError: Micro : Unsupported major.minor version 51.0 UnsupportedClassVersionError:Micro:不支持的major.minor版本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. 您已经用另一个系统上运行的JVM不支持的类版本编译了applet。

Use the -target flags for javac to produce class files for a given target JVM version. 使用javac-target标志来生成给定目标JVM版本的类文件。

UnsupportedClassVersionError
  • To compile code for a particular Java version, use the cross-compilation options . 要编译特定Java版本的代码,请使用交叉编译选项 To do this properly will require an rt.jar of the target version (to use the bootclasspath option of javac ). 要正确执行此操作,将需要目标版本的rt.jar (以使用javacbootclasspath选项)。
  • To deploy code that requires a particular version, use deployJava.js 要部署需要特定版本的代码,请使用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 . 为了保持理智提供更好的用户体验,请将小程序转换为应用程序,然后使用Java Web Start从链接启动它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM