AWT-EventQueue-0错误

时间:2013-03-18 15:48:14

标签: java awt keylistener

我写了以下代码。基本上我想激活自动完成(在RSyntaxTextArea环境中),如果输入的字符不是空格。一切都很顺利,但有时我会得到AWT-EventQueue-0错误。该程序仍将运行并运行,但会显示错误消息。

我的代码中有其他元素,但我确信这是来自这些添加的代码。有什么特别的原因吗?当我将鼠标移动到第二个屏幕时,我注意到发生了这个错误。

public static CompletionProvider provider = createModelCompletionProvider();

public static AutoCompletion ac = new AutoCompletion(provider);

public static KeyListener ListenerTOntology = new KeyListener() {

@Override
public void keyPressed(KeyEvent e) {}

@Override
public void keyReleased(KeyEvent e) {}

@Override
public void keyTyped(KeyEvent e) {
dumpInfo("Typed", e);}

private void dumpInfo(String s, KeyEvent e) {
    char temp = e.getKeyChar();
    if(temp!=' ' )
   ac.doCompletion();}
};

错误讯息:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at org.fife.ui.rtextarea.FoldIndicator.findOpenFoldClosestTo(FoldIndicator.java:162)
at org.fife.ui.rtextarea.FoldIndicator.access$300(FoldIndicator.java:60)
at org.fife.ui.rtextarea.FoldIndicator$Listener.mouseMoved(FoldIndicator.java:671)
at java.awt.AWTEventMulticaster.mouseMoved(AWTEventMulticaster.java:329)
at java.awt.Component.processMouseMotionEvent(Component.java:6550)
at javax.swing.JComponent.processMouseMotionEvent(JComponent.java:3339)
at java.awt.Component.processEvent(Component.java:6274)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4505)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.awt.EventQueue$3.run(EventQueue.java:686)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:702)
at java.awt.EventQueue$4.run(EventQueue.java:700)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:699)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

1 个答案:

答案 0 :(得分:0)

所以,我发现了导致这种情况的原因。您需要使用CaretListener而不是KeyListener。由于RSyntaxTextArea不包含DocumentListner。