File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.lang.ClassCastException: javax.swing.KeyStroke cannot be cast to java.lang.Comparable

 
annapoorna chitturi
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The SWING frame work that i am using is working fine with jre1.6.When i try to run it through jre1.7 getting the below exception .

java.lang.ClassCastException: javax.swing.KeyStroke cannot be cast to java.lang.Comparable
at java.util.TreeMap.compare(Unknown Source)
at java.util.TreeMap.put(Unknown Source)
at java.util.TreeSet.add(Unknown Source)

Can any one help to reslove this ..
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You know that a class cast can only cast an object to a type that it already is. If you look up KeyStroke, you find it doesn’t implement Comparable. I can tell that without looking in the API from the exception message you quoted. You may be able to sort by using the getKeyChar or getKeyCode methods, but I don’t know. You might have to use those methods inside the compare() method of a Comparator<KeyStroke>.
 
Darryl Burke
Bartender
Posts: 5116
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It might help if you explain why, when you want to map KeyStrokes, you choose to use TreeMap and not some other Map implementation.

Also, I can't see where the Java version should make a difference. Can you post the code that you say works in Java SE 6 but fails in 7, in the form of an SSCCE?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic