Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object is null

 
Pradeep Adibatla
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic