My simple applet won't run


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: My simple applet won't run

Threaded View

  1. #1
    Join Date
    Nov 2005
    Posts
    4

    My simple applet won't run

    This problem has been solved.
    The error:
    java.lang.ClassFormatError: Extra bytes at the end of class file
    Was caused by uploading the .class file in ascii format.




    I'm new to applets so hopefully my problem will be obvious to someone:
    I'm running windows XP, java 1.5.0_05

    I have a file called HelloWorld.java-

    import java.applet.Applet;
    import java.awt.Graphics;

    public class HelloWorld extends Applet {
    public void paint(Graphics g) {
    g.drawString("Hello world!", 50, 25);
    }
    }
    [eof]

    I run this through javac to get HelloWorld.class
    HelloWorld.class is uploaded to the same webpage in the same folder as index.htm-

    <html>

    <head>
    ...
    </head>

    <body>
    ...
    <APPLET CODE="HelloWorld.class" WIDTH=600 HEIGHT=450>
    </APPLET>
    ...
    </body>
    </html>


    The page comes up, loads java, then displays the big X. It's located on geocities, but I'm told that shouldn't be a problem.

    I opened the java console and it gives me a rather long list:


    java.lang.ClassFormatError: Extra bytes at the end of class file HelloWorld
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at sun.applet.AppletClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadCode(Unknown Source)
    at sun.applet.AppletPanel.createApplet(Unknown Source)
    at sun.plugin.AppletViewer.createApplet(Unknown Source)
    at sun.applet.AppletPanel.runLoader(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception in thread "Thread-137" java.lang.NullPointerException
    at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
    at sun.plugin.AppletViewer.showAppletException(Unknown Source)
    at sun.applet.AppletPanel.runLoader(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    java.lang.NullPointerException
    at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
    at sun.plugin.AppletViewer.showAppletStatus(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception in thread "thread applet-HelloWorld.class" java.lang.NullPointerException
    at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
    at sun.plugin.AppletViewer.showAppletException(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Last edited by coffeebreak; 11-12-2005 at 04:45 PM.

Similar Threads

  1. Problems getting an Applet to run off ftp
    By Manticor in forum Java
    Replies: 2
    Last Post: 05-29-2005, 02:27 AM
  2. Java applet window
    By crash75uk in forum Java
    Replies: 1
    Last Post: 04-20-2005, 04:32 PM
  3. URGENT!! help on CHAT APPLET
    By wahwgg in forum Java
    Replies: 0
    Last Post: 03-30-2003, 02:57 AM
  4. How do I Embed an applet and have it run?
    By Dave Brown in forum Enterprise
    Replies: 0
    Last Post: 08-25-2001, 03:51 PM
  5. Replies: 3
    Last Post: 08-23-2001, 12:01 PM

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