gpt4 book ai didi

java - 为什么我在 Java BasicTableUI$Handler.setValueIsAdjusting 中不断收到 NullPointerException?

转载 作者:行者123 更新时间:2023-11-29 09:58:33 26 4
gpt4 key购买 nike

我的应用程序中不断出现此 NPE,而且我似乎无法摆脱它,因为它没有出现在我的任何源代码中。正如您从堆栈跟踪中看到的那样,它没有发生在我的代码中,而是发生在 Swing plaf 中。你们中有没有人遇到过这个问题,也许知道这里发生了什么?

   11:28:23,273 [AWT-EventQueue-0] ERROR [is.althingi.styran.utlit.styran.StyranImpl]
- uncaughtException
java.lang.NullPointerException
at javax.swing.plaf.basic.BasicTableUI$Handler.setValueIsAdjusting(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI$Handler.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(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.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)

最佳答案

我设法解决了这个问题!

问题是我向我的 JTable 添加了一个 ListSelectionListener;在我的监听器的 valueChanged 方法中,我随后调用了 scrollRectToVisible,然后调用了 updateUI,这导致了我的异常。

我所做的是在 updateUI 调用周围添加 invokeLater 并且不再有异常!

像这样:

  SwingUtilities.invokeLater(new Runnable() {
public void run() {
updateUI();
}
});

既然我有了问题的“答案”(虽然我不确定我是否仍然理解为什么 invokeLater 有帮助?),但我认为我的问题还不够好。我没有提供足够的关于我的问题的信息,任何人都无法回答这个问题。在我问之前我应该​​更多地研究这个问题吗?我不知道。

也许我提供对我有帮助的解决方案就足够了!

关于java - 为什么我在 Java BasicTableUI$Handler.setValueIsAdjusting 中不断收到 NullPointerException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/340286/

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