• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

applet not initialized

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Is WelcomeApplet part of package "ch16"? If so, it needs to be inside a directory called "ch16", not directly in the same directory as the HTML file.
 
tung kee
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ulf Dittmer:
Welcome to JavaRanch.

Is WelcomeApplet part of package "ch16"? If so, it needs to be inside a directory called "ch16", not directly in the same directory as the HTML file.





Thank you! I knew it was just some bonehead error that would take 2 seconds to correct. I moved the html file above the "ch16" directory and it worked. I've got a loooong way to go on this java path.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.

I've got a loooong way to go on this java path.



Make sure to take a step every day -even if it's just a tiny step-, and you'll be well on your way before you know it. If you have problems, come back here and let us know about them. We'll try to help.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic