Why am I getting a NullPointerException
when I call getParameter()
in this very simple JApplet
instantiation?
public class TestPad extends javax.swing.JApplet {
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
TestPad appletDefn = new TestPad();
TestPad.sSomeParam = (String)appletDefn.getParameter("sSomeParam");
appletDefn.init();
appletDefn.start();
}
});
}
private static String sSomeParam = "sSomeArg";
}
No security policy file, no other packages, and only two libraries: a) swing-layout-1.0.4.jar b) JDK-1.6 (default)
The implementation of the method in the
Applet
class:So the method call on
transient private AppletStub stub
throws the exception.Applets have an other lifecycle than a normal application. I suggest you to take a look at the official Java tutorials on Applets.