问题描述
所以我为一个我认识的孩子写了一个贪吃蛇游戏的代码,这个该死的东西不会嵌入到 html 中.
So I wrote my code for a Snake game for a kid I know and the darned thing won't embed itself in html.
<html>
<head>
<title>Snake</title>
</head>
<body>
<applet width=200 height=100 code="SnakeGame.class">
</applet>
</body>
</html>
并且我确定该类文件与 snake.html
位于同一目录中,但它仍然拒绝运行.它总是回复:
and I am certain that the class file is in the same directory as snake.html
, but it still refuses to run. It always replies:
java.lang.NoClassDefFoundError: SnakeGame (wrong name: view/SnakeGame)
有人知道为什么吗?谢谢.
Does anyone know why? Thanks.
文件夹view
包含:SnakeGame.class
,以及游戏的所有其他类,以及html
the folder view
contains: SnakeGame.class
, and all the other classes for the game, as well as the html
推荐答案
看起来 SnakeGame
类在 view
包中,所以你的小程序标签应该是这样的:
It seems that SnakeGame
class in in the view
package, so your applet tag should look like:
<applet width=200 height=100 code="view.SnakeGame.class">
通常你在'code'属性中指定'package.class',即com.stackoverflow.MyClass.class
Generally you specify 'package.class' in the 'code' attribute, i.e. com.stackoverflow.MyClass.class
这篇关于尝试嵌入小程序时出现 java.lang.NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!