Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

AWT-EventQueue-0" java.lang.ClassCastException

7 views
Skip to first unread message

patrick

unread,
Aug 20, 2005, 12:21:42 PM8/20/05
to

Ive got a swing application with quite a lot of code. With several JFrames
being created at various stages.
Its working fine but Im getting this ClassCastException sometimes at no
predictable time or place in my code.So I cant find the source of the
problem with normal debugging.

Anybody any ideas on how to find the problem here??

TIA
patrick


Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException
at javax.swing.LayoutComparator.compare(LayoutComparator.java:72)
at java.util.Arrays.mergeSort(Arrays.java:1284)
at java.util.Arrays.mergeSort(Arrays.java:1296)
at java.util.Arrays.mergeSort(Arrays.java:1295)
at java.util.Arrays.mergeSort(Arrays.java:1295)
at java.util.Arrays.mergeSort(Arrays.java:1296)
at java.util.Arrays.sort(Arrays.java:1223)
at java.util.Collections.sort(Collections.java:159)
at
javax.swing.SortingFocusTraversalPolicy.enumerateAndSortCycle(SortingFocusTraversalPolicy.java:119)
at
javax.swing.SortingFocusTraversalPolicy.getFirstComponent(SortingFocusTraversalPolicy.java:425)
at
javax.swing.LayoutFocusTraversalPolicy.getFirstComponent(LayoutFocusTraversalPolicy.java:148)
at
javax.swing.SortingFocusTraversalPolicy.getDefaultComponent(SortingFocusTraversalPolicy.java:502)
at
java.awt.FocusTraversalPolicy.getInitialComponent(FocusTraversalPolicy.java:149)
at
java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:318)
at java.awt.Component.dispatchEventImpl(Component.java:3841)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.SequencedEvent.dispatch(SequencedEvent.java:93)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)


Roedy Green

unread,
Aug 21, 2005, 2:56:49 AM8/21/05
to
On Sat, 20 Aug 2005 17:21:42 +0100, "patrick" <netwo...@eircom.net>
wrote or quoted :

>javax.swing.SortingFocusTraversalPolicy.enumerateAndSortCycle(SortingFocusTraversalPolicy.java:119)

It appears to be dying trying to sort the components in focus
traversal order.

Something in that list is not designed to be compared with the
Comparable being used by the sort.

For general background, have a look at
http://mindprod.com/jgloss/focus.html on how write a custom
FocusTraversal policy.

Presumably you wrote a Comparator on two Components. You had better
not have made any presumption about the compare parms other than
Component, since Swing has various hidden Components (such as in a
JSpinner) to help implement the official component that will end up
being compared.

Presumably, you then fed this Comparator to
SortingFocusTraversalPolicy and hooked it up as your official policy.
It then died when your comparator was fed something it could not
handle with a cast exception.

I'm guessing you presumed only YOUR components with some special field
would be passed to the comparator, and something else got passed in.

You need to catch the cast exception and print out the classes of the
two objects you were supposed to compare. Find out what they are, and
make your Comparator smart enough to handle them. You might have to
find an associated object to compare instead.

0 new messages