在JApplet中调用getParameter()时发生InvocationTargetException

时间:2012-07-11 01:04:03

标签: java applet invocationtargetexception

我在Java 7中有一个JApplet,每次我想在浏览器中启动它时,InvocationTargetException来自getParameter()的{​​{1}}。这是我的堆栈跟踪:

JApplet

我的HTML文件如下所示:

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.runOnEDTAndWait(Unknown Source)
    at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.instantiateApplet(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager.initAppletAdapter(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
    at com.sun.deploy.uitoolkit.impl.awt.OldPluginAWTUtil.invokeAndWait(Unknown Source)
    ... 5 more
Caused by: java.lang.NullPointerException
    at java.applet.Applet.getParameter(Unknown Source)
    at TicTacToe.TicTacToeAppletView.<init>(TicTacToeAppletView.java:34)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter$1.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

在与HTML文件相同的文件夹中,有一个名为TicTacToe的文件夹,其中包含所有必需的类文件(当然,否则我会得到<applet code="TicTacToe/TicTacToeAppletView.class" width="400" height="400"> <param name=Size value="4"> </applet> )。

如果我不使用getParameter(),它可以正常工作。使用此方法的Java代码看起来像:

ClassNotFoundException

那到底是什么造成了这么多麻烦?

1 个答案:

答案 0 :(得分:1)

参数名称Size不应该在引号中吗?

<param name="Size" value="4">

有关使用参数的更多信息,请查看Defining and Using Applet Parameters Tutorial