Populating a TreeMap throws NullPointerException?

I looks like AccountGroupBean doesn't implement Comparable in a proper way, try to println group. CompareTo(group) to check if it prints 0.

This is most likely a problem with how the AccountGroupBean class is implementing equals and hashcode. There are some rules fro implementing equals and hashcode that you should make sure your code complies to. Some of the rules for the equals method include.

Reflexive for any non null value x. Equals(x) is always true Symetric for non null values y. Equals(x) must return true if and only if x.

Equals(y) is true Transitive for non null values if x. Equals(y) is true and y. Equals(z) is true then x.

Equals(z) must also be true Consistant The equals method should return the same answer during multiple invocations if the objects have not been modfied. If two objects are equal their hashcoe method should return the same value.

I do not implement equals nor hashcode. Should I? – Sergio del Amo Nov 8 '10 at 11:57 1 @Sergio, no unless you want to consider several instances of the AccountGroupBean as equals for example new AccountGroupBean(1).

Equals(new AccountGroupBean(1)) will be false unless you implement equals , and if you implement equals you should also implement hashcode consistently... – pgras Nov 8 '10 at 12:03 1 This is useful information, but TreeMap relies on compareTo rather than on hashcode and equals like a hashmap... – pgras Nov 8 '10 at 12:06 @pgras +1 you are right. I did not know this. I always thought that compareTo was just used on insert for sortinging purposes.

You learn something new everyday. – mR_fr0g Nov 8 '10 at 12:09.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions