• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Object is null

 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();


reply
    Bookmark Topic Watch Topic
  • New Topic