• Post Reply Bookmark Topic Watch Topic
  • New Topic

NullPointerException under an IF statement which should be skipped  RSS feed

 
Noffica Rostt
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


When year is outside the 1993-2009 range, I get a NullPointerException from line 10. Shouldn't it be skipped entirely since the conditions of its parent IF statement (line 7) is not met?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inspect your if statement very carefully.
 
Jhakda Velu
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to find out what may cause Nullpointer Exception in line 10 of your code, what could be null there? Also, why do you think line 7 will help in skipping lines 8-18.
Try to test your line 7 if condition with values 1992, 1995 and 2010.

I believe you are assuming that nobelPrizeWinners.get(year) will give proper value for years 1993-2009.

 
Noffica Rostt
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.

Yet another case of PEBCAK.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More a tautology sneaking past you unnoticed.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!