• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Problem with new Objects

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using TreeMap


And I am adding to the TreeMap my key (uaKey) and a new UnitAssetData object. This is the correct signature for the UnitAssetData constructor and this seems to work fine.

I am doing this so that I can sort the UnitAssetData object by their key.



Later on I am retriveing them and they do appear in the order that I want. However there appears to be no UnitAssetData object in the TreeMap



The output shows that the key is there, but the UnitAssetData is all null.

I know when I create the object using new I don't give the new objects a reference, but I didn't think I had to. Especially as I don't need/use it. Is my logic flawed?

key is IOBB20070411
null null
key is IODD20070411
null null
key is IOFF20070411
null null
key is IOPPTEX990KPT90920070411:11
null null
key is IOQQ20070411
null null
key is IOZZ20070411
 
Ranch Hand
Posts: 2410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show the code in the UnitAssetData class?
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[PJ:]I know when I create the object using new I don't give the new objects a reference, but I didn't think I had to. Especially as I don't need/use it. Is my logic flawed?


No, I think so it's correct.

There is a UnitAssetData in the TreeMap. Had uaD been null it would had thrown a nullPointerException at System.out.println(uaD.getRksFundName()+" "+uaD.getCusipID());.

When you are adding a UnitAssetData Object see what you have in rksFundName and cusipID.
[ May 10, 2007: Message edited by: Anupam Sinha ]
 
Paul James
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you are adding a UnitAssetData Object see what you have in rksFundName and cusipID.

There shouldn't be a problem with this data, I'm using the same data to create the key



The UnitAssetData class is fairly straightforward, a Constructor and some getters

 
Paul James
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops!!

I think I can see it, my constructor is wrong.
 
Paul James
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This fixed it.

Thanks and sorry for posting a stupid one.



[ May 11, 2007: Message edited by: Paul James ]
[ May 11, 2007: Message edited by: Paul James ]
 
I brought this back from the farm where they grow the tiny ads:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic