【发布时间】:2012-11-20 09:02:06
【问题描述】:
我们的小程序源代码有点像意大利面条(写于 2000 年,当时是 Java 1.3),我们希望将其重新编译为 Java 1.6 或 1.7。
当我测试它时,大部分 Swing 都可以,但过了一段时间,出现了 Exception,这是 EDT 异常。具体来说,当拖动事件完成时,会出现一系列 EDT 异常。
这与在ActionListeners 中对 I/O 部分进行编码有关吗?因为我已经读到在动作侦听器中编写 I/O 操作是不好的,EDT 在执行动作时执行该操作。
编辑:
这是反复出现的异常
Exception in thread "AWT-EventQueue-3" java.lang.NullPointerException
at javax.swing.BufferStrategyPaintManager.flushAccumulatedRegion(Unknown Source)
at javax.swing.BufferStrategyPaintManager.copyArea(Unknown Source)
at javax.swing.RepaintManager.copyArea(Unknown Source)
at javax.swing.JViewport.blitDoubleBuffered(Unknown Source)
at javax.swing.JViewport.windowBlitPaint(Unknown Source)
at javax.swing.JViewport.setViewPosition(Unknown Source)
at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.vsbStateChanged(Unknown Source)
at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.stateChanged(Unknown Source)
at javax.swing.DefaultBoundedRangeModel.fireStateChanged(Unknown Source)
at javax.swing.DefaultBoundedRangeModel.setRangeProperties(Unknown Source)
at javax.swing.DefaultBoundedRangeModel.setValue(Unknown Source)
at javax.swing.JScrollBar.setValue(Unknown Source)
at javax.swing.plaf.basic.BasicScrollBarUI$TrackListener.setValueFrom(Unknown Source)
at javax.swing.plaf.basic.BasicScrollBarUI$TrackListener.mouseDragged(Unknown Source)
at java.awt.Component.processMouseMotionEvent(Unknown Source)
at javax.swing.JComponent.processMouseMotionEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$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)
【问题讨论】:
-
这很可能是由于非 EDT 线程访问 UI 代码。 UI 代码只能由 EDT 访问。关于 IO,EDT 应该很少这样做 - 查看
SwingWorker的 IO 代码。 -
拖动操作如何导致 I/O?如果是为了“拖动时显示的图标”之类的东西,那么应该在启动时加载图标。
-
异常是由拖动滚动条或使用拖动动作调整表格列大小引起的...我添加了异常堆栈..谢谢
-
这是不是和jar包没有打包的applet有关..因为我们所做的就是将class文件直接嵌入到html文件中
标签: java swing io applet event-dispatch-thread