gpt4 book ai didi

java - Java Applet 中的 ClassNotFoundException

转载 作者:行者123 更新时间:2023-12-01 09:50:09 25 4
gpt4 key购买 nike

我有一个非常基本的 Java 小程序,它无法在 Safari 中运行,作为一本无法运行的旧教科书的练习。我在 OSX El Capitan 上使用旧版 Java SDK 1.6 版。 HTML 是

<html>
<head>
<title>2-1 Test</title>
</head>
<body>
<applet code="HelloWorld.class"></applet>
</body>
</html>

Java程序是:

import java.awt.*;
import java.applet.*;

public class HelloWorld extends java.applet.Applet{
TextField m1, m2, m3;
public void main(){
m1 = new TextField(60);
m2 = new TextField(60);
m3 = new TextField(60);
m1.setText("Good day to you!");
m2.setText("My name is Cynthia.");
m3.setText("This is the third line.");
add(m1);
add(m2);
add(m3);
}
}

HTML和Java文件(编译为HelloWorld.class)位于同一目录中(不涉及包)。

更新:空格已从文件路径中删除。 Java 控制台现在出现以下内容:

basic: tap installed
basic: Creating PluginEmbeddedFrame served by PlaceHolderServerName-2581
basic: Done creating PluginEmbeddedFrame
basic: Added progress listener: sun.plugin.util.ProgressMonitorAdapter@7e29e923
security: Expected Main URL: file:/Users/Desktop/GreatIdeasInComputerScienceWithJavaExercises/HelloWorld.class
java.lang.ClassNotFoundException: HelloWorld.class
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(ClassLoader.java:357)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.initAppletAdapter(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
basic: load: class HelloWorld.class not found.
java.lang.ClassNotFoundException: HelloWorld.class
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(ClassLoader.java:357)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.initAppletAdapter(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
security: Accessing keys and certificate in Mozilla user profile: null
security: Reset deny session certificate store
security: Reset deny session certificate store
basic: Removed progress listener: sun.plugin.util.ProgressMonitorAdapter@7e29e923
basic: Dialog type is not candidate for embedding
basic: Dialog type is not candidate for embedding

任何人都可以建议我需要做什么才能正确设置 Java,以便我可以继续阅读这本书吗?

最佳答案

main 方法中的内容放入 initrun 方法中。小程序通常没有 main 方法。

话虽如此,小程序现在已被弃用,并且通常不再受支持,大多数(如果不是全部)浏览器都主动阻止它们,并且 Oracle 决定取消对小程序插件的支持。

也许你应该仔细看看 How to use Applets

已更新

现在错误已更改,这表明您尚未编译 .java 文件和/或未在您期望的位置编译该文件

关于java - Java Applet 中的 ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37646018/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com