Applet的麻烦 - 的NoClassDefFoundError [英] Applet trouble - NoClassDefFoundError
问题描述
我知道有这些职位的一百万,但他们都没有帮我所以这里有云:我想部署一个非常,非常简单的小程序将无法正常加载。
我的HTML:
< HTML和GT;
< HEAD>
< META HTTP-EQUIV =Content-Type的内容的text / html;字符集= UTF-8>
< /头>
<身体GT;
<小程序code =SimpleApplet.class
宽度=320HEIGHT =100>&下; /小程序>
< /身体GT;
< / HTML>
我的Java:
封装测试;进口的javax.swing *。公共类SimpleApplet扩展JApplet的{
公共无效的init(){
尝试{
SwingUtilities.invokeAndWait(新的Runnable(){
公共无效的run(){
JLabel的LBL =新的JLabel(的Hello World);
加(LBL);
}
});
}
赶上(例外五){
的System.out.println(E);
}
}
}
这两个文件都位于同一目录
/家庭/ ME /工作区/ myProject的/斌/测试
如果我通过Eclipse运行其自己的小程序,它工作正常。当我打开网页出现错误
java.lang.NoClassDefFoundError的:SimpleApplet(错误的名称:测试/ SimpleApplet)
该错误将表明我没有正确放置或命名的东西。然而,试图在
<小程序code =测试/ SimpleApplet.class
宽度=320HEIGHT =100>&下; /小程序><小程序code =SimpleApplet.class
codeBase类=/测试
宽度=320HEIGHT =100>&下; /小程序>
连同其他尝试,包括删除,试图绝对和所有的部分路径名,以及使用的.java,它仍然不工作,我最终得到一个ClassNotFoundException。<一个href=\"http://stackoverflow.com/questions/11396646/load-class-myapplet-not-found-java-lang-classnotfoundexception-why-am-i-gett\">Other <一href=\"http://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror-in-java\">answers指出,类路径和codeBase的(通常与归档)问题是发生这种情况,但我没有使用一个jar文件的主要原因和两个文件都在同一目录下。任何人都知道这是为什么发生?
- /家庭/ ME /工作区/ myProject的/ bin中
- applet.html
- /家庭/ ME /工作区/ myProject的/斌/测试
- SimpleApplet.class
如果该类 SimpleApplet
是包测试
放在父目录的HTML(详见上文)并使用这个HTML。
&LT; HTML和GT;
&LT; HEAD&GT;
&LT; META HTTP-EQUIV =Content-Type的内容的text / html;字符集= UTF-8&GT;
&LT; /头&GT;
&LT;身体GT;
&LT;小程序code =test.SimpleApplet
宽度=320HEIGHT =100&GT;&下; /小程序&GT;
&LT; /身体GT;
&LT; / HTML&GT;
侧面提示:
- 在当前张贴code,后期进口和封装声明为好,或者换句话说,这一切。由于这是我们需要做的事情的猜测;但与全code,我们就不会去。
- 在这个阶段不要尝试小程序。你应该理清在命令行上包工作,和小应用程序比使用GUI应用程序更加困难。
I realize there's a million of these posts but none of them have helped me so here goes: I'm trying to deploy a very, very simple applet that will not load properly. My HTML:
<html>
<head>
<meta http-equiv="Content-Type" content"text/html; charset=utf-8">
</head>
<body>
<applet code = "SimpleApplet.class"
width = "320" height = "100"></applet>
</body>
</html>
My Java:
package test;
import javax.swing.*;
public class SimpleApplet extends JApplet{
public void init(){
try{
SwingUtilities.invokeAndWait(new Runnable(){
public void run(){
JLabel lbl = new JLabel("Hello World");
add(lbl);
}
});
}
catch(Exception e){
System.out.println(e);
}
}
}
Both files are located in the same directory
/home/me/workspace/myProject/bin/test
If I run the applet on its own via Eclipse, it works fine. When I open the page I get the error
java.lang.NoClassDefFoundError: SimpleApplet (wrong name: test/SimpleApplet)
The error would suggest that I have incorrectly placed or named something. However, after trying
<applet code = "test/SimpleApplet.class"
width = "320" height = "100"></applet>
<applet code = "SimpleApplet.class"
codebase = "/test"
width = "320" height = "100"></applet>
along with other attempts, including removing the ", trying absolute and all partial path names, and using .java, it still does not work and I end up getting a ClassNotFoundException. Other answers point out that classpath and codebase (often relating to archive) issues are a primary reason for this occurring. However, I am not using a jar file and both files are in the same directory. Anyone know why this is occurring?
- /home/me/workspace/myProject/bin
- applet.html
- /home/me/workspace/myProject/bin/test
- SimpleApplet.class
If the class SimpleApplet
is in package test
put the HTML in the parent directory (as detailed above), and use this HTML.
<html>
<head>
<meta http-equiv="Content-Type" content"text/html; charset=utf-8">
</head>
<body>
<applet code = "test.SimpleApplet"
width = "320" height = "100"></applet>
</body>
</html>
Side tips:
- When posting code, post the imports and package statement as well, or in other words, all of it. As it is we need to make guesses about things; but with the full code, we would not have to.
- Don't attempt applets at this stage. You should sort out working with packages on the command line, and applets are more difficult than applications with a GUI.
这篇关于Applet的麻烦 - 的NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!