java.lang.reflect.InvocationTargetException whilst locally running an applet (no server)

395 views Asked by At

I'm trying to load an applet on a simple HTML page that I've written (I also wrote the applet) but it throws an InvocationTargetException every time. The applet works when I run it in Eclipse, but I can't get it to work on the webpage.

HTML:

<html>
<center>
<applet archive = "OneMove.jar" code = "main.TheApplet.class" width = "1000" height = "500"></applet>
</center>
</html>

TheApplet.class:

package main;

import java.awt.BorderLayout;
import java.lang.reflect.InvocationTargetException;

import javax.swing.*;

public class TheApplet extends JApplet {
    private static final long serialVersionUID = 7088647188194272265L;

    protected Display display0 = new Display();

    public void init() {

        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    setLayout(new BorderLayout());
                    add(display0);
                }
            });
        } catch (InvocationTargetException e) {
            e.printStackTrace();
            e.getCause();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void start() {
        display0.start();
    }

    public void stop() {
        display0.stop();
    }

}

If there's any other piece of code you need from me, just ask and I will post.

Need an answer sooner rather than later, too:p

Thanks all!

1

There are 1 answers

0
Ebrahim Amini Sharifi On

If you compiled you applet with jdk 1.6 you must use jre 6 for browser.