Java 加载:找不到类com.example.helloworld.helloworld.class
我正在学习Youtube上Java教程中的Applet。当我使用IntelliJ编写代码时,一切都进行得很顺利。小程序查看器也工作得很好 但是,当我将小程序代码插入html文件(我将其命名为Java 加载:找不到类com.example.helloworld.helloworld.class,java,html,intellij-idea,applet,noclassdeffounderror,Java,Html,Intellij Idea,Applet,Noclassdeffounderror,我正在学习Youtube上Java教程中的Applet。当我使用IntelliJ编写代码时,一切都进行得很顺利。小程序查看器也工作得很好 但是,当我将小程序代码插入html文件(我将其命名为index.html)中,并将HelloWorld.class复制到桌面(包含主要内容)时,我打开index.html,然后在浏览器中发现为空 这是我的HelloWorld.java&index.html HelloWorld.java index.html 运行applet viewer index.h
index.html
)中,并将HelloWorld.class
复制到桌面(包含主要内容)时,我打开index.html,然后在浏览器中发现为空
这是我的HelloWorld.java
&index.html
HelloWorld.java
index.html
运行applet viewer index.html时,出现如下错误
java.lang.NoClassDefFoundError: /Users/Peterhon/Desktop/HelloWorld (wrong name: com/example/helloworld/HelloWorld)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:217)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:152)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:626)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:804)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:733)
at sun.applet.AppletPanel.run(AppletPanel.java:378)
at java.lang.Thread.run(Thread.java:745)
谁能给我一个提示吗
HelloWorld.class
“假设您使用windows”,即:javac HelloWorld.java
,这将生成HelloWorld.class
——确保HelloWorld.class
和.html文件位于同一位置,比如说C:
驱动器中<applet code="/Users/Peterhon/Desktop/HelloWorld.class" width="400" height="100"></applet>
关于这一行:
<applet code="HelloWorld.class" width="400" height="100"></applet>
localhost//test.html
在您的计算机中为applet类提供实际路径,例如
@JBALI我已经尝试过这样做,但仍然得到了上面更新过的类似错误。我希望您能看到:-)这里的code属性
应该是类的完全限定名,因此
。@AndrewThompson您什么意思???您不明白什么?(请注意,添加四个“?”根本无助于澄清。)我使用了mac,但我已经完成了第一步和第二步,就像你在这里写的那样。但我不知道如何在上面迈出第三步mac@PeterTsung“但我不知道如何在mac上执行第三步”小程序需要经过数字签名,公众才能看到它。一旦小程序被数字签名,上述建议的第3部分就变得完全不相关了。@AndrewThompson谢谢你,Thompson.:-)
<applet code="HelloWorld.class" width="400" height="100"></applet>