To get meaningful advice, you really need to post a lot more information than you've given us, for example, you're obviously running this code somehow, but I don't see a main method anywhere. I haven't tried, but I'm pretty sure that the code you've given us won't compile, so something is definitely missing between what you're seeing and what you're telling us that you're seeing.
Also, just saying that you remember it was a NullPointerException isn't really enough - you should have a stack trace that tells you exactly where the exception was thrown, among other things - all of that is useful information.
also, be sure you read the book carefully. There are many examples in the book that are not meant to be complete, executable code samples, but just enough code to illustrate a point. It is not all meant to be typed up, compiled and run.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors