Sir/Madame,
I have what it is probably a very basic question, but cannot figure why my
applet will not work. I am using Eclipse 3.2.1, running jdk 1.6.0 on a Windows XP machine.
java code:
import javax.swing.*;
public class WelcomeApplet extends JApplet {
public WelcomeApplet() {
add(new JLabel("Welcome to Java", JLabel.CENTER));
}//end constructor
}//end class
html code:
<html>
<head>
<title>Welcome Java Applet</title>
</head>
<body>
<applet
code = "WelcomeApplet.class"
width = 350
height = 200>
</applet>
</body>
</html>
My .java, .class, and .html files are all in the same directory. When I run the program as an applet from within Eclipse it runs fine. When I open the html file, it shows an outline with a red X in the top left corner (in both Firefox and IE). When I run the appletviewer I get the following error message:
C:\eclipse\workspace\JavaIntro\ch16>appletviewer WelcomeApplet.html
java.lang.NoClassDefFoundError: WelcomeApplet (wrong name: ch16/WelcomeApplet)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
4)
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:163)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:119)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:591)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:721)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:650)
at sun.applet.AppletPanel.run(AppletPanel.java:324)
at java.lang.Thread.run(Thread.java:595)
I tried adding "codebase" to the html file but then nothing showed up in the web page. Please let me know if you need any other information.
Thanks.