-
NoClassDefFoundError when trying to run an applet
Hi,
I'm new to java and am having a problem when I try to run an applet. It compiles OK, but when I try to run it using the appletviewer the console window shows this message:
java.lang.NoClassDefFoundError: HelloApplet (wrong name: fund2/lesson1/HelloApplet)
The last bit (fund2/lesson1) is the last bit of the path to the HelloApplet.
and the applet window shows:
Start: applet not initialized
The code for the applet is:
Code:
import java.applet.Applet;
import java.awt.*;
public class HelloApplet extends Applet {
public void paint(Graphics graArg) {
graArg.drawString("Hello World!", 50, 100);
}
}
The code for the html is:
Code:
<html>
<h1>Hello Applet Example</h1>
<object code="HelloApplet.class"
height=200
width=300>
</object>
</html>
Not even the H1 title appears in the applet window.
The Classpath variable does contain the path to my applet folder and both the class and html files are in the same folder under this path.
I hope someone can suggest where I'm going wrong as I've been tearing my hair out trying to get this working.
Thanks in anticipation.
Debbie-Leigh
Debbie Figg runs Quick-Computer-Solutions.com - your One Stop Solution Shop to your computer problems covering every problem area you would come across.
-
wasnt this fixed on codeguru.com? i dunno.. i forget which boards i do what on..
-
Hi cjard,
Yes it was. I forgot that I had asked on this forum too.
For anyone here who is interested, here is the solution:
It was that I'd left a commented out package statement at the top of the file. I didn't think that it would have any effect as it was commented out, but when I deleted it the applet started working.
Someone has pointed out to me though, that applets can be in a package, but you have to put the complete package path to the applet in the code statement in the html file to make sure it works e.g.
<APPLET CODE="package.path.to.the.applet.AppletName"
WIDTH=200 HEIGHT=200>
</APPLET>
I've also subsequently found out that if you use a package statement in an applet, then the html file needs to be in a different directory above applet in the directory tree or in another directory tree. In the latter case, the applet statement in the html file needs to have a codebase statement specifying where the applet is relative to the html file e.g. ../java/code.
I hope that helps.
Debbie-Leigh
Debbie Figg runs Quick-Computer-Solutions.com - your One Stop Solution Shop to your computer problems covering every problem area you would come across.
-
though i do believe i pointed out that applet is now deprecated; the preferred way of placing a java applet on a page is using the object tag
further notes, on your solution; the codebase forms the effective equivalent of the classpath. if you are using a main class that is a member of a package, then it must be named in accordance with package naming rules.
for a complete explanation about classpathing, see my post to monkey_man in this thread:
http://forums.javaboutique.internet....&threadid=1813
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks