• Post Reply Bookmark Topic Watch Topic
  • New Topic

Program doesn't complete, but no errors?  RSS feed

 
Alex Birmingham
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all,

I'm compiling the following code just fine, but it doesn't execute certain lines, specifically the ones after accessing HashMap roomList in some way. The part that really confuses me is that I'm not recieving any compile or runtime errors.



Thanks!

[ June 23, 2008: Message edited by: Alex Birmingham ]
[ June 23, 2008: Message edited by: Alex Birmingham ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is why you're not seeing the errors:

} catch(Exception ex) { }

Don't do that, ever. Always report exceptions in some way -- just ex.printStackTrace() is totally fine.

You're getting NullPointerExceptions in makeRoomA()/makeRoomB() because the member roomList is uninitialized (i.e., it's null). You've made an error that it seems most folks new to Java make just once; after this, you'll remember. Instead of assigning to the member roomList in createRoomGrid(), you're declaring a new local variable by the same name which is said to "shadow" or "hide" the member variable. The member remains null, while the HashMap you so lovingly create is surrendered to the garbage collector at the end of createRoomGrid().

To be specific, if you need it: the line

HashMap roomList = new HashMap();

should just be

roomList = new HashMap();

including the type turns this line into a declaration of a new variable.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!