appletviewer 中的 JApplet / JRE1.6.0_30 — getParameter(“someArg”) 上的 NullPointerException
当我在这个非常简单的 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";
}
没有安全策略文件,没有其他包,只有两个库: a) swing-layout-1.0.4.jar b) JDK-1.6(默认)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Applet
类中该方法的实现:因此对
transient private AppletStub Stub
的方法调用会引发异常。Applet 具有与普通应用程序不同的生命周期。我建议您看一下关于 Applet 的官方 Java 教程。
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.
init()
和run()
。它在任何时候都不会调用main(String[])
。init()
andrun()
. At no time would it call themain(String[])
.main(String[])
, not using the applet viewer. Running it that way will cause an NPE because there has been no applet context/stub set up and initialized. It takes some work to do so.