2013-03-18 90 views
0

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

*“我的代码中有其他元素,但我确定它是来自添加代码的这一点。”*堆栈跟踪应该告诉你。发布[SSCCE](http://sscce.org/),我们也可能知道。 – 2013-03-18 15:50:23

+0

那么'FoldIndicator.findOpenFoldClosestTo'中的代码是什么? 'FoldIndicator.java'的第162行? – 2013-03-18 15:52:20

+0

这是RSyntaxTextArea.jar文件。我找不到源文件来查看它里面的内容。我期待着。 – Artemis 2013-03-18 15:56:02

回答

0

所以,我发现是什么原因造成这一点。您需要使用CaretListener而不是KeyListener。由于RSyntaxTextArea不包含DocumentListner。