开发者

java.lang.NoClassDefFoundError when trying to embed an applet

开发者 https://www.devze.com 2023-01-08 00:36 出处:网络
So I wrote my code for a Snake game for a kid I know and the darned thing won\'t embed itself in 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>Sna开发者_JAVA百科ke</title>
</head>
<body>
<applet width=200 height=100 code="SnakeGame.class">
</applet>
</body>
</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.

EDIT:

the folder view contains: SnakeGame.class, and all the other classes for the game, as well as the html


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">

Generally you specify 'package.class' in the 'code' attribute, i.e. com.stackoverflow.MyClass.class

0

精彩评论

暂无评论...
验证码 换一张
取 消