gpt4 book ai didi

java - ClassCastException 的未知来源(在 JTables 中)

转载 作者:行者123 更新时间:2023-12-01 16:41:51 27 4
gpt4 key购买 nike

我目前正在重构一个 JTable,它显示多种不同类型的数据。这种重构的主要原因是存在一些 ClassCastExceptions (编写代码的作者/ friend 已经中断),而且我似乎无法找到这些异常的来源。由于代码库庞大,我不知道从哪里开始。有没有人有什么建议?我意识到这个问题的含糊之处并对此表示歉意!

我在下面添加了堆栈跟踪。谢谢!!

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean    at javax.swing.JTable$BooleanRenderer.getTableCellRendererComponent(Unknown Source)    at javax.swing.JTable.prepareRenderer(Unknown Source)    at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)    at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)    at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)    at javax.swing.plaf.ComponentUI.update(Unknown Source)    at javax.swing.JComponent.paintComponent(Unknown Source)    at javax.swing.JComponent.paint(Unknown Source)    at javax.swing.JComponent.paintToOffscreen(Unknown Source)    at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)    at javax.swing.RepaintManager.paint(Unknown Source)    at javax.swing.JComponent._paintImmediately(Unknown Source)    at javax.swing.JComponent.paintImmediately(Unknown Source)    at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)    at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)    at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)    at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)    at java.awt.event.InvocationEvent.dispatch(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)

最佳答案

BooleanRenderer 中发生的此错误是因为它期望来自表模型的值的类型为 Boolean 并尝试转换为它(akf 的答案具有其出现的确切代码行)。

我的猜测是,最初预计模型将为给定列返回 boolean 值,但在某一时刻它会返回字符串。因此,我将集中精力于这个给定的表使用什么模型(它是自定义模型吗?它是向其中添加值的默认模型吗?)并查看它可能在哪里获取 String 而不是 boolean 值

关于java - ClassCastException 的未知来源(在 JTables 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/978192/

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