[英]JApplet in appletviewer / JRE1.6.0_30 — NullPointerException on getParameter(“someArg”)
Why am I getting a NullPointerException
when I call getParameter()
in this very simple JApplet
instantiation? 当我在这个非常简单的
JApplet
实例化中调用getParameter()
时,为什么会出现NullPointerException
?
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) 没有安全策略文件,没有其他包,只有两个库:a)swing-layout-1.0.4.jar b)JDK-1.6(默认)
The implementation of the method in the Applet
class: Applet
类中方法的实现:
public String getParameter(String name) {
return stub.getParameter(name);
}
So the method call on transient private AppletStub stub
throws the exception. 因此,对
transient private AppletStub stub
的方法调用会抛出异常。
Applets have an other lifecycle than a normal application. Applet具有除正常应用程序之外的其他生命周期。 I suggest you to take a look at the official Java tutorials on Applets .
我建议你看一下关于Applets的官方Java教程 。
init()
and run()
. init()
和run()
。 At no time would it call the main(String[])
. main(String[])
。 main(String[])
, not using the applet viewer. main(String[])
来运行'applet',而不是使用applet viewer。 Running it that way will cause an NPE because there has been no applet context/stub set up and initialized.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.