java.lang.NoClassDefFoundError when trying to embed an applet

对着背影说爱祢 提交于 2019-12-20 07:38:45

问题


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>

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


回答1:


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



来源:https://stackoverflow.com/questions/3298988/java-lang-noclassdeffounderror-when-trying-to-embed-an-applet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!