Errata Listing 33.9 (Digital Version)


#1

In the updateUI() method in RunFragment.java it says:

[code] private void updateUI() {
boolean started = mRunManager.isTrackingRun();

    if (mRun != null)
        mStartedTextView.setText(mRun.getStartDate().toString());

    int durationSeconds = 0;
    if (mRun != null && mLastLocation != null) {
        durationSeconds = mRun.getDurationSeconds(mLastLocation.getTime());
        mLatitudeTextView.setText(Double.toString(mLastLocation.getLatitude()));
        mLongitudeTextView.setText(Double.toString(mLastLocation.getLongitude()));
        mAltitudeTextView.setText(Double.toString(mLastLocation.getAltitude()));
    }
    mDurationTextView.setText(Run.formatDuration(durationSeconds));
    
    mStartButton.setEnabled(!started);
    mStopButton.setEnabled(started);

}
[/code]

I get a compile time NullPointerException at the line when I launch the app for the first time:

I think there are 2 errors here:
1.) “Run.formatDuration” should be "mRun.formatDuration"
2.) The “mDurationTextView.setText” line should be inside the “if” block to check that mRun != null

Let me know if this sounds right.

Other than that, thanks for making this book - I am enjoying every minute of it!


#2

Nevermind - I did not realize that formatDuration(…) is a static method in the Run class.

The below code

is correct and should be outside of the “if” statement as is written in the book.