Code to initialize mDate missing from Kindle version


#1

I bought the kindle version of this book not too long ago and have been happily chugging through. Got a null point exception when I tried to run the example (p153) and finally realized that I needed to add mDate = new Date() to the Crime constructor. This code wasn’t in my version of the book as far as I can tell.


#2

How did you come to this conclusion, did you get an error with

public Date getDate() { return mDate; }

I have the Kindle version, but did not get any such error, but my app crashed so something is off. But all the other variables in Crime.java are not technically initialized either, so not sure if that’s it. Did initializing mDate fix your app?

UPDATE:

I tried adding the mDate initialization code as you suggested and it worked. Maybe because Date was coming in as an import, it needed to be initialized in the Crime() method? I don’t think I understand WHY this worked, but sure glad it works, because I was getting no errors at all and only a “ThrottleService” error in my LogCat (which I had no idea was that was)… so thanks a lot for pointing this out!! :slight_smile:


#3

Spookily I had the same issue in that I had failed to initialise mDate and I have a physical book rather than an eBook. Anyway, after much hunting down, I found my error and the code to initialise this was on page 149 so I’m wondering if others may have missed this.

This is what the code for Crime.java should begin with:

[code]public class Crime {

private UUID mId;
private String mTitle;
private Date mDate;
private boolean mSolved;

public Crime() {
	// Generate unique identifier
	mId = UUID.randomUUID();
	mDate = new Date();
}[/code]