Java Swing和事件错误?

时间:2012-02-08 19:15:38

标签: java multithreading swing events awt-eventqueue

我一直在运行游戏服务器而且我收到此错误。我还不熟悉java,所以请帮帮我。 我有几个活动经理来处理玩家事件,比如木刻或采矿,也许事件没有正确停止,我不确定。 你能解释一下awt事件队列是什么吗?

当我们让游戏服务器运行超过一天时会发生这种情况。可能每12小时左右就会发生一次。

[2/8/12 11:00 AM]: Exception in thread "AWT-EventQueue-0" [2/8/12 11:00 AM]: jav
a.lang.ArrayIndexOutOfBoundsException: 14 >= 14
[2/8/12 11:00 AM]:      at java.util.Vector.elementAt(Unknown Source)
[2/8/12 11:00 AM]:      at javax.swing.DefaultListModel.getElementAt(Unknown Sou
rce)
[2/8/12 11:00 AM]:      at javax.swing.plaf.basic.BasicListUI.paintCell(Unknown
Source)
[2/8/12 11:00 AM]:      at javax.swing.plaf.basic.BasicListUI.paintImpl(Unknown
Source)
[2/8/12 11:00 AM]:      at javax.swing.plaf.basic.BasicListUI.paint(Unknown Sour
ce)
[2/8/12 11:00 AM]:   at javax
.swing.plaf.ComponentUI.update(Unknown Source)

[2/8/12 11:00 AM]:      at javax.swing.JComponent.paintComponent(Unknown Source)
[2/8/12 11:00 AM]:      at javax.swing.JComponent.paint(Unknown Source)
[2/8/12 11:00 AM]:      at javax.swing.JComponent.paintChildren(Unknown Source)
[2/8/12 11:00 AM]:      at javax.swing.JComponent.paint(Unknown Source)
[2/8/12 11:00 AM]:      at javax.swing.JViewport.paint(Unknown Source)
[2/8/12 11:00 AM]:      at javax.swing.JComponent.paintChildren(Unknown Source)
[2/8/12 11:00 AM]:      at javax.swing.JComponent.paint(Unknown Source)
[2/8/12 11:00 AM]:      at javax.swing.JComponent.paintToOffscreen(Unknown Sourc
e)
[2/8/12 11:00 AM]:      at javax.swing.BufferStrategyPaintManager.paint(Unknown
Source)
[2/8/12 11:00 AM]:      at javax.swing.RepaintManager.paint(Unknown Source)
[2/8/12 11:00 AM]:      at javax.swing.JComponent._paintImmediately(Unknown Sour
ce)
[2/8/12 11:00 AM]:      at javax.swing.JComponent.paintImmediately(Unknown Sourc
e)
[2/8/12 11:00 AM]:      at javax.swing.RepaintManager.paintDirtyRegions(Unknown
Source)
[2/8/12 11:00 AM]:      at javax.swing.RepaintManager.paintDirtyRegions(Unknown
Source)
[2/8/12 11:00 AM]:     at javax
.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)

[2/8/12 11:00 AM]:      at javax.swing.RepaintManager.access$700(Unknown Source)

[2/8/12 11:00 AM]:      at javax.swing.RepaintManager$ProcessingRunnable.run(Unk
nown Source)
[2/8/12 11:00 AM]:      at java.awt.event.InvocationEvent.dispatch(Unknown Sourc
e)[2/8/12 11:00 AM]: Npc deleted

[2/8/12 11:00 AM]:      at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
[2/8/12 11:00 AM]: Npc deleted

[2/8/12 11:00 AM]:      at java.awt.EventQueue.access$000(Unknown Source)[2/8/12
 11:00 AM]: Npc deleted

[2/8/12 11:00 AM]:      at java.awt.EventQueue$3.run(Unknown Source)[2/8/12 11:0
0 AM]: Npc deleted

[2/8/12 11:00 AM]:      at java.awt.EventQueue$3.run(Unknown Source)
[2/8/12 11:00 AM]: Npc deleted[2/8/12 11:00 AM]:        at java.security.AccessC
ontroller.doPrivileged(Native Method)

[2/8/12 11:00 AM]:      at java.security.ProtectionDomain$1.doIntersectionPrivil
ege(Unknown Source)
[2/8/12 11:00 AM]:
at java.awt.EventQueue.dispatchEvent(Unknown Source)

[2/8/12 11:00 AM]:      at java.awt.EventDispatchThread.pumpOneEventForFilters(U
nknown Source)
[2/8/12 11:00 AM]:      at java.awt.EventDispatchThread.pumpEventsForFilter(Unkn
own Source)
[2/8/12 11:00 AM]:      at java.awt.EventDispatchThread.pumpEventsForHierarchy(U
nknown Source)
[2/8/12 11:00 AM]:      at java.awt.EventDispatchThread.pumpEvents(Unknown Sourc
e)
[2/8/12 11:00 AM]:      at java.awt.EventDispatchThread.pumpEvents(Unknown Sourc
e)
[2/8/12 11:00 AM]:      at java.awt.EventDispatchThread.run(Unknown Source)

2 个答案:

答案 0 :(得分:2)

我猜你正在更新事件调度线程之外的组件状态,这可能会导致问题。

也许Concurrency in Swing会有所帮助。

答案 1 :(得分:1)

关于事件队列:当您拥有使用图形用户界面(GUI)的应用程序时,还有一个与此GUI关联的线程。该线程运行一个循环,等待鼠标点击等事件。如果需要更改某些内容(例如,使用更多数据更新列表),该线程也应该更新GUI上的控件

GUI线程操作来自所谓的事件队列的更改。需要更新GUI的其他线程需要将其更新转发到GUI线程,这是将它们添加到事件队列的过程,因为只有GUI线程才能实际应用它们。

在此处阅读更多相关信息:http://www.kauss.org/Stephan/swing/index.html