Java exception occurred: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Character

瀏覽次數:40 次
跳到第一則未讀訊息

Alexandre Depouhon

未讀,
2015年4月23日 清晨5:38:102015/4/23
收件者:tablefil...@googlegroups.com
Hi,

I am using the table filter package within a GUI developped in Matlab; the table model to which it is appended extends the DefaultTableModel proposed in Swing. It works fine 99% of the time. However, yesterday I encountered an error with a specific data set. The following error message is thrown when I enable the AutoChoices feature:

Java exception occurred:
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Character
 at java.lang.Character.compareTo(Unknown Source)
 at net.coderazzi.filters.gui.ParserModel$3.compare(ParserModel.java:428)
 at net.coderazzi.filters.gui.ParserModel$3.compare(ParserModel.java:426)
 at net.coderazzi.filters.gui.editor.ChoicesListModel.compare(ChoicesListModel.java:324)
 at net.coderazzi.filters.gui.editor.ChoicesListModel.compare(ChoicesListModel.java:55)
 at java.util.TreeMap.put(Unknown Source)
 at java.util.TreeSet.add(Unknown Source)
 at net.coderazzi.filters.gui.editor.ChoicesListModel.addContent(ChoicesListModel.java:169)
 at net.coderazzi.filters.gui.editor.PopupComponent.addChoices(PopupComponent.java:119)
 at net.coderazzi.filters.gui.editor.FilterEditor.addChoices(FilterEditor.java:402)
 at net.coderazzi.filters.gui.editor.FilterEditor.setChoices(FilterEditor.java:392)
 at net.coderazzi.filters.gui.AdaptiveChoicesHandler$AdaptiveChoicesSupport$EditorHandle.iterationCompleted(AdaptiveChoicesHandler.java:648)
 at net.coderazzi.filters.gui.AdaptiveChoicesHandler$AdaptiveChoicesSupport.extractChoices(AdaptiveChoicesHandler.java:442)
 at net.coderazzi.filters.gui.AdaptiveChoicesHandler$AdaptiveChoicesSupport.rowsAdded(AdaptiveChoicesHandler.java:268)
 at net.coderazzi.filters.gui.AdaptiveChoicesHandler$AdaptiveChoicesSupport.<init>(AdaptiveChoicesHandler.java:227)
 at net.coderazzi.filters.gui.AdaptiveChoicesHandler.createAdaptiveChoicesSupport(AdaptiveChoicesHandler.java:145)
 at net.coderazzi.filters.gui.AdaptiveChoicesHandler.setInterrupted(AdaptiveChoicesHandler.java:79)
 at net.coderazzi.filters.gui.FiltersHandler.enableNotifications(FiltersHandler.java:447)
 at net.coderazzi.filters.gui.FiltersHandler.setAutoChoices(FiltersHandler.java:239)
 at net.coderazzi.filters.gui.TableFilterHeader.setAutoChoices(TableFilterHeader.java:287)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at com.mathworks.jmi.AWTUtilities$Invoker$3$1.call(AWTUtilities.java:466)
 at com.mathworks.mvm.context.ThreadContext.callWithContext(ThreadContext.java:105)
 at com.mathworks.mvm.context.MvmContext.callWithContext(MvmContext.java:113)
 at com.mathworks.jmi.AWTUtilities$Invoker$3.runWithOutput(AWTUtilities.java:463)
 at com.mathworks.jmi.AWTUtilities$Invoker$2.watchedRun(AWTUtilities.java:416)
 at com.mathworks.jmi.AWTUtilities$WatchedRunnable.run(AWTUtilities.java:377)
 at java.awt.event.InvocationEvent.dispatch(Unknown Source)
 at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
 at java.awt.EventQueue.access$200(Unknown Source)
 at java.awt.EventQueue$3.run(Unknown Source)
 at java.awt.EventQueue$3.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.security.ProtectionDomain$1.doIntersectionPrivilege(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)

I have been able to identify the data set that is causing the issue which is apparently related to the casting of some of the data displayed in the table. Nevertheless, visual inspection does not reveal any difference between the trouble makers and the data sets that work. Would you have any suggestion as to how I could pinpoint the cause of this problem?

Thanks.
Alex

coderazzi

未讀,
2015年4月23日 清晨5:59:202015/4/23
收件者:tablefilter-swing
Hi, Alex,

the problem normally appears when the data does not conform to the model.
That is, in your model you define getColumnClass to specify which type
is returned for that column, and the data that you supply must then
match each column's class.
Then, it looks as your data includes in a column a Character when it
should contain a String (or the opposite)

Does this help you?

Best regards,

Lu/
> --
> You received this message because you are subscribed to the Google Groups
> "tablefilter-swing" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to tablefilter-sw...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Alexandre Depouhon

未讀,
2015年4月23日 清晨7:04:312015/4/23
收件者:tablefil...@googlegroups.com
Hello Luis,

that does make some sense and helped me find the issue. According to the table model, the column classes are defined after the type of data that appears on the first line of the table. For the data set that is causing problem, one cell on that first line contains a single character, whence the defined type java.lang.Character, while on some other lines cells in that same column contain several characters and correspond to the type java.lang.String.

I still have to figure out a fix for such situations but at least I know where to look. Thanks for pointing me in the right direction.

Best,
Alex

You received this message because you are subscribed to a topic in the Google Groups "tablefilter-swing" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tablefilter-swing/L8TWLZNR_8w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tablefilter-sw...@googlegroups.com.
回覆所有人
回覆作者
轉寄
0 則新訊息