In one of my classes say Test, in static block of it; i am constructing map using an object of type BakidRangeid as key and Integer as value. My hashmap declaration looks as below.
public static HashMap<BakidRangeid, Integer> mapBankIdRangeIdToConfId = new HashMap<BakidRangeid, Integer> ();
And BakidRangeid class looks like
public class BakidRangeid {
private int bankId;
private int rangeId;
public int getBankId() {
return bankId;
}
public void setBankId(int bankId) {
this.bankId = bankId;
}
public int getRangeId() {
return rangeId;
}
public void setRangeId(int rangeId) {
this.rangeId = rangeId;
}
}
When i am trying to get the value from hashmap mapBankIdRangeIdToConfId by setting instance of an BakidRangeid, i get NullpointerException inspite of the object with values of bankid and rangeid, which i am passing is present in the hashmap. I guess i will have to override equals and hashcode methods of my BakidRangeid class. Anyone kindly confirm. Thanks in advance!