AWT EventQueue NullPointerException

时间:2010-04-19 13:58:08

标签: java applet

我有一个签名小程序,它将文本文件写入客户端工作站中的指定目录。

当我第一次在网络浏览器中加载小程序时,没有问题。它设法在浏览器中加载并将数据写入文本文件。但是当我继续再次加载它时,它就不会加载。我看到的只是Java加载图像。即使在等待10分钟后,小程序仍然无法加载。

不幸的是,这并不是一直发生的。我已经尝试关闭Web浏览器并清除所有缓存和临时文件,但有时它会再次发生。

客户端工作站安装了JRE 1.6.0_16,并且在IE8上测试的Windows XP上运行。

下面是HTML页面中的Applet标记代码。

<applet code="com.applet.files.PrintTkt.class" archive="<%=BaseURL %>/UT/SPrintTkt.jar" width="500" height="450">
    <param NAME="ROOT" value="<%= BaseURL %>">
    <param NAME="CHARSET" value="<%= charset %>">
    <param NAME="batfile" value="<%= batfile %>">
    <param NAME="filename" value="<%= filename %>">
    <param NAME="PAGE_ID" value="PrintTkt">
</applet>

以下是Java控制台的堆栈跟踪。仅当我刷新页面,转到另一个页面或从我们的Web应用程序注销时,才会抛出以下异常。在此之前,堆栈跟踪仅显示Applet正在加载。

basic: Loading Java Applet ...
basic: Applet initialized
basic: Removed progress listener: sun.plugin.util.GrayBoxPainter$GrayBoxProgressListener@59a34
basic: Applet made visible
basic: Starting applet
basic: completed perf rollup
basic: Applet started
basic: Told clients applet is started
Exception in thread "AWT-EventQueue-6" java.lang.NullPointerException
    at java.awt.LightweightDispatcher$3.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(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)
Exception in thread "AWT-EventQueue-6" java.lang.NullPointerException
    at java.awt.LightweightDispatcher$3.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(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)
Exception in thread "AWT-EventQueue-6" java.lang.NullPointerException
    at java.awt.LightweightDispatcher$3.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(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)

1 个答案:

答案 0 :(得分:0)

之前我遇到过这种变种。当重新加载包含applet的页面时,它可以重用类加载器,前提是它还没有最终确定。发生这种情况时,不会重新加载已由该类加载器加载的类。这可能会导致静态成员出现一些令人讨厌的问题。该类已经加载,因此类静态不会重新初始化。并且,您最终得到一个非null的类静态,但它保存的值不再有效。

检查代码中的静态成员并尽可能消除。如果无法消除它们,请在applet stop方法中添加钩子,将静态值设置为null。