Can you please provide a complete source code snippet ? What are you putting in the ArrayList exactly ?
Regards ...
Vassili ...
SCJP 5.0, SCWCD 1.4, SCJA 1.0
Dorcas Rebanha
Greenhorn
Joined: Apr 04, 2007
Posts: 18
posted
0
Ummm, the agentList contains AgentDisplayObjects, and I don't know more than that. Somebody else wrote the code and I am just trying to understand it, and possibly fix that pesky ClassCastException.
Are you suggesting that the contents of agentList might the problem?
I originally thought simply that you couldn't addAll() an ArrayList into a TreeSet. So I was hoping for advice about getting around that, like maybe a different method to use to accomplish the purpose.
TreeSet requires that the objects that you put into it implement interface Comparable.
You get this exception because your class AgentDisplayObject does not implement Comparable.
Note, if you can't modify class AgentDisplayObject, then you can use the constructor of class TreeSet that takes a Comparator as an argument (see the API documentation of class TreeSet). When you do that, your class AgentDisplayObject does not need to implement Comparable - the comparator that you pass to the constructor will be responsible for sorting AgentDisplayObject objects instead.