gpt4 book ai didi

java - MATLAB 报告 "Exception in thread "AWT-EventQueue- 0"java.lang.NullPointerException"

转载 作者:搜寻专家 更新时间:2023-11-01 00:59:01 26 4
gpt4 key购买 nike

我想知道一个在 MATLAB 中反复出现的 Java 错误。它通常发生在 MATLAB 使用 Java 执行一些繁重的工作时。例如,这可以是按住 Ctrl + ZCtrl + Y

我在复制之前错误地删除了错误信息,但我认为我无论如何都能通过问题的核心。

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
...
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

为什么会出现这个错误?我从 MATLAB r2007 中找到了一些关于此的信息,这是由于 Java Swing线程不安全并且 MATLAB 缺乏支持以确保 thread safety .但是,这应该已在 MATLAB r2008b 中修复。那为什么我现在得到它?

这是完整的堆栈跟踪:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at org.netbeans.editor.BaseDocument.notifyUnmodify(BaseDocument.java:1465)
at org.netbeans.editor.BaseDocument.notifyModifyCheckEnd(BaseDocument.java:816)
at org.netbeans.editor.BaseDocumentEvent.redo(BaseDocumentEvent.java:336)
at javax.swing.undo.UndoManager.redoTo(Unknown Source)
at javax.swing.undo.UndoManager.redo(Unknown Source)
at com.mathworks.mwswing.undo.MUndoManager.redo(MUndoManager.java:255)
at org.netbeans.editor.ActionFactory$RedoAction.actionPerformed(ActionFactory.java:767)
at org.netbeans.editor.BaseAction.actionPerformed(BaseAction.java:259)
at javax.swing.SwingUtilities.notifyAction(Unknown Source)
at javax.swing.JComponent.processKeyBinding(Unknown Source)
at javax.swing.JComponent.processKeyBindings(Unknown Source)
at javax.swing.JComponent.processKeyEvent(Unknown Source)
at com.mathworks.widgets.SyntaxTextPaneBase.processKeyEvent(SyntaxTextPaneBase.java:1187)
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.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(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)

最佳答案

好吧,根据您的堆栈跟踪,您的问题可能没有任何明确的答案,正如您已经在 MATLAB 的论坛中看到的那样,但是鉴于这一行,我认为有一个可能的解释:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
...
at javax.swing.undo.UndoManager.redoTo(Unknown Source) // <-- here!
at javax.swing.undo.UndoManager.redo(Unknown Source)
at com.mathworks.mwswing.undo.MUndoManager.redo(MUndoManager.java:255)
...

UndoManager类保留内部集合 UndoableEdit对象。这个集合实际上继承自它的父类(super class):CompoundEdit .

UndoManager#redo()的内部实现和 UndoManager#redoTo(UndoableEdit edit)看起来像这样:

public class UndoManager extends CompoundEdit implements UndoableEditListener {
...
public synchronized void redo() throws CannotRedoException {
if (inProgress) {
UndoableEdit edit = editToBeRedone();
if (edit == null) {
throw new CannotRedoException();
}
redoTo(edit);
} else {
super.redo();
}
}
...
protected void redoTo(UndoableEdit edit) throws CannotRedoException {
boolean done = false;
while (!done) {
UndoableEdit next = edits.elementAt(indexOfNextAdd++);
next.redo(); // NPE here?
done = next == edit;
}
}
...
}

考虑到这个实现并考虑到 Swing 的 Event Dispatch Thread (EDT)很容易出问题,我想可能是MATLAB线程和EDT之间的线程问题。具体来说,这个 MATLAB 调用的方法可能是问题的根源:

at com.mathworks.mwswing.undo.MUndoManager.redo(MUndoManager.java:255)

既然你说 MATLAB 需要做繁重的工作,那么认为这种方法试图重做一些可能不再可用或可能不可用的编辑并不是没有道理的/em>,由于与 EDT 的同步问题。

关于java - MATLAB 报告 "Exception in thread "AWT-EventQueue- 0"java.lang.NullPointerException",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25015983/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com