NoClassDefFoundError when trying to run an applet


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: NoClassDefFoundError when trying to run an applet

  1. #1
    Join Date
    Feb 2004
    Posts
    4

    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.

  2. #2
    Join Date
    Feb 2004
    Posts
    808
    wasnt this fixed on codeguru.com? i dunno.. i forget which boards i do what on..
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

  3. #3
    Join Date
    Feb 2004
    Posts
    4
    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.

  4. #4
    Join Date
    Feb 2004
    Posts
    808
    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
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center