1

I have a very simple Test program that just opens up a JFrame and I want to open it in browser. I know I have to self sign it to open it but it throws just this error:

java.lang.reflect.InvocationTargetException

I have signed the jar with the JARMAKER

My HTML to load the jar:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
  </head>
  <body>
    <p>Inhalt der Webseite</p>

    <applet code=Simple_Frame.class
        archive="Simple_Frame2.jar"
        width="120" height="120">
</applet>
  </body>
</html>

The simple Test program:

    import java.applet.Applet;
import java.awt.*;

/**
 * Created by Flex on 22.10.14.
 */
public class Start extends Applet{

    public static void main(String[] args) {

        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                Simple_Frame ex = new Simple_Frame();
                ex.setVisible(true);
            }
        });
    }
}


import javax.swing.JFrame;

public class Simple_Frame extends JFrame {

    public Simple_Frame() {

        setTitle("Simple example");
        setSize(300, 200);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
}

How can I open a Jar in a webpage on my localhost to test it without that error and what does this error mean?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
AliceInChains
  • 167
  • 1
  • 1
  • 9
  • 1) Why code an applet? If it is due to the teacher specifying it, please refer them to [Why CS teachers should **stop** teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). 2) Why use AWT? See [this answer](http://stackoverflow.com/questions/6255106/java-gui-listeners-without-awt/6255978#6255978) for many good reasons to abandon AWT using components in favor of Swing. 3) That HTML is invalid. It declares itself as HTML 4.01, but the `applet` element was deprecated by then. – Andrew Thompson Oct 22 '14 at 23:11

1 Answers1

1
<applet code=Simple_Frame.class
    archive="Simple_Frame2.jar"
    width="120" height="120">

The first thing that jumps out at me, is that Simple_Frame is not an applet. The Start class is though.

<applet code=Start
    archive="Simple_Frame2.jar"
    width="120" height="120">

Another tip is that InvocationTargetException is usually a wrapper for another more specific exception. Always copy/paste the full error and exception output!

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433