TreeMap error

I have several TreeMap classes in the app I'm working on and one is acting funny. The Class I'm 'putting' into the Map includes Integer, Strings and Calendar objects. After loading the Map I go through the keys (integer values) loading the values to a table control and find that all of the values are the same. In this case the values are the last member that was added. I step through the 'put' method and the varies are correct but when I use the Map they are all the same. Very strange. The Class I'm putting into the Map implements comparable and the key is an Integer value in natural order.I don't really care about order I want to be able to access Map members via the key value in any order using the 'get' method. Has anybody run into this problem and is there a work-around?I'm using 1.6 and XP.

Your assistance is greatly appreciated.

[870 byte] By [ThrowCodea] at [2007-11-27 7:35:11]
# 1

It sounds familiar, lots of people have reported similar things. But "workaround" isn't the right word for what you need to do. There's a bug in your code and you need to fix it.

The usual culprits are: (1) you only have one object and you keep changing its properties, so you can only see the last set of properties you set (2) your class has its properties declared as static, so ditto.

But if neither of those work for you, post some of your code.

DrClapa at 2007-7-12 19:15:41 > top of Java-index,Core,Core APIs...
# 2
Thanks Doctor (Tomatos/Tomatos) - FYI ?I found that I had to substitute the Date class for the Calendar (Gregorian) class to make the Map work properly. Changing to object failed, using String with GregorianCalendar.toString() failed. Does anyone know why this is?
ThrowCodea at 2007-7-12 19:15:41 > top of Java-index,Core,Core APIs...
# 3

> Thanks Doctor (Tomatos/Tomatos) - FYI ?I found that

> I had to substitute the Date class for the Calendar

> (Gregorian) class to make the Map work properly.

> Changing to object failed, using String with

> GregorianCalendar.toString() failed. Does anyone

> know why this is?

Can't say without seeing your code. I have no idea what you're saying here.

jverda at 2007-7-12 19:15:41 > top of Java-index,Core,Core APIs...
# 4

I'm saying that the ANSWER to the error was to substitute the Date Class for the GregorianCalendar Class in the definition of the new class that I created for the applicaiton. The class that I wanted to put into the Map.

THAT FIXED THE PROBLEM - but in no way explains the reason for the problem. I call that a work-around - not very satisfactory!

ThrowCodea at 2007-7-12 19:15:41 > top of Java-index,Core,Core APIs...
# 5
Again, I'm not going to try to reconstruct your code in my head so that I can explain why one works and the other doesn't.All I can say for sure is that the issue is one of you not understanding how certain classes or methods are intended to be used.
jverda at 2007-7-12 19:15:41 > top of Java-index,Core,Core APIs...
# 6

Well, if you want an explanation you will have to ask somebody who can see your code. Right now you're the only one who fits that description. But you could remedy that by posting the code here. Don't waste your time by ranting any more. Either post the code or shut up.

Generally it isn't a good idea to change things randomly until your error stops happening. It's better to understand what's going on so you know why your change appeared to work. But you already know that -- not very satisfactory, you said. So let's find out what's wrong with your code.

DrClapa at 2007-7-12 19:15:41 > top of Java-index,Core,Core APIs...
# 7

I've never understand that approach:

"There's something wrong with my code. I do some stuff, and then something goes wrong. How do I fix it?"

"We can't answer that without seeing the code."

"I already told you the problem! I DO SOME STUFF AND THEN SOMETHING GOES WRONG! NOW HOW DO I FIX IT!?!?!?"

jverda at 2007-7-12 19:15:41 > top of Java-index,Core,Core APIs...
# 8
I'm also curious why he's using a TreeMap if he doesn't care about the order.
ejpa at 2007-7-12 19:15:41 > top of Java-index,Core,Core APIs...
# 9
I抦 using Map so that I can use the 慘ey?to selectively retrieve a specific member of the Map as needed (order is not important)!
ThrowCodea at 2007-7-12 19:15:41 > top of Java-index,Core,Core APIs...
# 10
> (order is not important)!Then you want HashMap, rather than TreeMap.
jverda at 2007-7-12 19:15:41 > top of Java-index,Core,Core APIs...