我使用Eclipse创建了一个Java游戏。它有11个类(有一个主类可以调用其他所有类)。我通过以下方式将其称为applet:
<!-- This is the applet handler to load the Handler Class to run the game -->
<td colspan="3"><applet code="Handler.class" codebase="History Adventure Alamo Adventure/" name="Alamo Battle Adventure" width="680" height="509" archive="Handler.jar" id="Alamo Battle Adventure">
</applet></td>
随着它上传到网站,它显示一个错误,并告诉我点击查看详细信息。当我选择它时,它会告诉我ClassNotFoundException:Handler.class
代码在身体中,我头脑中没有任何东西。我做错了什么?
以下是该页面的其余代码。实际测试页面可在www.kluckhohndesign.com上找到
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script language="javascript" type="text/javascript">
<!--
function popitup(url) {
newwindow=window.open(url,'name','height=510,width=500');
if (window.focus) {newwindow.focus()}
return false;
}
// -->
</script>
<title>Alamo Battle Adventure</title>
</head>
<body>
<blockquote> </blockquote>
<table width="1300" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="318" height="160"> </td>
<td colspan="3"><img src="Alamo Battle Adventure.jpg" width="680" height="160" alt="Top Banner" /></td>
<td width="318"> </td>
</tr>
<tr>
<td> </td>
<td width="226"><a href="howtoplay.html" onclick="return popitup('howtoplay.html')"><img src="How to Play.jpg" width="226" height="52" alt="How to Play" /></a></td>
<td width="226"> </td>
<td width="227"><a href="Help.html" onclick="return popitup('help.html')"><img src="help.jpg" width="226" height="52" alt="Help" /></a></td>
<td> </td>
<tr>
<td><img src="Alamo Pencil.jpg" width="318" height="250" alt="Alamo Drawing" /></td>
<!-- This is the applet handler to load the Handler Class to run the game -->
<td colspan="3"><applet code="Handler.jar" codebase="History Adventure Alamo Adventure/" name="Alamo Battle Adventure" width="680" height="509" archive="Handler.jar" id="Alamo Battle Adventure" />
</applet></td>
<td><img src="texans.jpg" width="318" height="250" alt="Texans Drawing" /></td>
</tr>
<tr>
<td> </td>
<td colspan="3"> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td colspan="3"> </td>
<td> </td>
</tr>
</table>
</body>
</html>
答案 0 :(得分:2)
这可以让你更进一步:
<html>
<body>
<applet
code="Handler"
codebase="http://www.kluckhohndesign.com/History%20Adventure%20Alamo%20Adventure/"
name="Alamo Battle Adventure"
width="680"
height="509"
archive="Handler.jar"
id="Alamo Battle Adventure" >
</applet>
</body>
</html>
您可以在代码库中省略http://www.kluckhohndesign.com/
前缀。
现在它会导致InvocationTargetException
。但是问一个新问题。
code
属性应该是类&amp;的完全限定名称。与罐子无关。大多数人认为FQN等于Handler.class
但实际上只是Handler
。History%20Adventure%20Alamo%20Adventure/
。它需要%20
空格,因为空格在URL中无效。然后,由于这个原因,大多数部署者都不会使用带空格的目录名。applet
元素从未打算像原始页面中显示的那样“自我关闭”。相反,它需要一个明确的</applet>
结束元素。