File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems with Java.lang.ClassCastException

 
Katy Parsons
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to create a poker game for my CS project but I keep getting a java.lang.ClassCastException error and I don't know where it's coming from....

This is the game class, which I believe is where the error is coming from:


And here is the error that is showing up:
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The stack trace shows you that the problem is here at Game.checkRoyalFlush(Game.java:294).
It also shows you that you are trying to sort an array whose element does not implements the Comparable interface. Check the sort() method of the java.util.Arrays class for more details.



slots is of type GVstack[], so the question is : Does GVstack implements Comparable ?
 
Katy Parsons
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, what can I do so that my array elements implement the comparable interface? Our Professor just told us to use the sort method for arrays and didn't go into any explanation.
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, what can I do so that my array elements implement the comparable interface?


Well, you can actually "implement the java.lang.Comparable interface"? The purpose of the interface is to provide a method that allows your element to be compared to another element -- this is needed, because it is not possible to sort an array, if the sort algorithm can't tell which element comes first.

Henry
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic