问题就是用eclipse写了个applet,用了package,然后创建一个html文件,嵌入applet后无法运行,如果不用package,而直接把程序拷到defaultpackage的文件中却可以。http://topic.csdn.net/u/20080913/13/2d33fec4-c4a3-4349-b3d7-06fadce7d024.html
忽略了package的后果
源文件helloapplet.java因为在package applet中,所以在源文件第一行会有这样一行东西:
package applet;在eclipse里运行小应用程序没有问题,但是用ie浏览器运行html文件,或者用appletviewer命令运行html文件,都会抛出classnot found的异常。
helloapplet.html代码如下:
<html>
<head>
<title>Hello Applet!</title>
</head>
<body>
<applet code="helloapplet.class" width=300height=100>
</applet>
</body>
</html><applet code="helloapplet.class"codebase="D:\eclipseworkspace\helloworld\bin\applet" width=300height=100>
</applet>
codebase指出class文件所在的基地目录,但是还是报相同的错误,折腾了很久,后来光华版友指出,错误和源文件第一行package语句有关。
于是想到引用包内定义类的格式应该是applet.helloapplet,那么对应的二进制文件引用方法也应该改为applet.helloapplet.class。于是做出<applet code="applet.helloapplet.class"codebase="D:\eclipseworkspace\helloworld\bin" width=300height=100>
</applet>
如此就ok了~:)
忽略了package的后果
源文件helloapplet.java因为在package applet中,所以在源文件第一行会有这样一行东西:
package applet;在eclipse里运行小应用程序没有问题,但是用ie浏览器运行html文件,或者用appletviewer命令运行html文件,都会抛出classnot found的异常。
helloapplet.html代码如下:
<html>
<head>
<title>Hello Applet!</title>
</head>
<body>
<applet code="helloapplet.class" width=300height=100>
</applet>
</body>
</html><applet code="helloapplet.class"codebase="D:\eclipseworkspace\helloworld\bin\applet" width=300height=100>
</applet>
codebase指出class文件所在的基地目录,但是还是报相同的错误,折腾了很久,后来光华版友指出,错误和源文件第一行package语句有关。
于是想到引用包内定义类的格式应该是applet.helloapplet,那么对应的二进制文件引用方法也应该改为applet.helloapplet.class。于是做出<applet code="applet.helloapplet.class"codebase="D:\eclipseworkspace\helloworld\bin" width=300height=100>
</applet>
如此就ok了~:)