Originally posted by Linda Xu:
Hi, I have some weird Exception in my code, when I have this line:
int costScore = ((Integer)myHT.get("costScore")).intValue();
It gives me a run time exception: java.lang.Integer
To fix it, I just seperate it into two lines:
Integer tmpCostScore =(Integer)myHT.get("costScore");
int costScore = tmpCostScore.intValue();
then the Exception is gone. Why? Thanks for any input.
Ashik Uzzaman
Director of Engineering, Twin Health, Mountain View, CA, USA
Jason R. Kretzer<br />Software Engineer<br />System Administrator<br /><a href="http://alia.iwarp.com" target="_blank" rel="nofollow">http://alia.iwarp.com</a>
Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
"I'm not back." - Bill Harding, Twister
Originally posted by Jim Yingst:
Personally, I find nothing unreadable about this line either. However, what happens if get("costScore") returns null? NullPointerException is what. For a robust program, chances are good that you'll want to split long lines like this up for better error checking.
Don't get me started about those stupid light bulbs. |