| Author |
Object is null
|
Pradeep Adibatla
Ranch Hand
Joined: Oct 27, 2009
Posts: 336
|
|
I have 2 classes A and B...
I want to use a HashMap(having get,set) of classA in classB...
This is what I did classB...
classA is null...
what should be corrected in the above?
|
 |
Embla Tingeling
Ranch Hand
Joined: Oct 22, 2009
Posts: 237
|
|
Pradeep Adibatla wrote:
what should be corrected in the above?
You need to assign objects to the variables you declare, otherwise they will be null.
For this to work properly you most likely will have to override the equals and hashCode methods of ClassA.
|
 |
Pradeep Adibatla
Ranch Hand
Joined: Oct 27, 2009
Posts: 336
|
|
|
I have the hashmap ready in classA object..I need to use it here.. If I create with new it becomes a new Class A object and it's hashmap will contain nothing since it is a new object isn't it?
|
 |
Pradeep Adibatla
Ranch Hand
Joined: Oct 27, 2009
Posts: 336
|
|
Let me elaborate...
In classA, hash map ,say I have 3 records like empNo,Employee
Now I need to get 3 values in class B... This is what I require...
HashA =new HashA<String,Emloyee>
HashA.put("1",ABC);
HashB.put("2",XYZ);
HashC.put("3",LMN);
In CLassB:-->
If I do ClassA classA =new ClassA();
// This would mean a new object isn't it?
I have HashB=new HAshB<String,Employee>
I wrote...
HashB=classA.getHashA();
|
 |
 |
|
|
subject: Object is null
|
|
|