Hi,
I keep receiving a NullPointerException and have been unable to find a way to resolve it. Any assistance would be much appreciated.
public class FitnessFrog extends Frog { // instance variable private int totalDistanceSprinted; private Random randomNumber; public FitnessFrog sporty1; public FitnessFrog sporty2; // constructor /** * Constructor for objects of class FitnessFrog. */ public FitnessFrog() { super(); this.randomNumber = new Random(); this.totalDistanceSprinted = 0; } /** * Setter for totalDistanceSprinted. */ private void setTotalDistanceSprinted(int aValue) { this.totalDistanceSprinted = aValue; } /** * Getter for totalDistanceSprinted. */ public int getTotalDistanceSprinted() { return this.totalDistanceSprinted; } /** * Sets the value of the totalDistanceSprinted variable to 0. * Returns no value. */ public void resetTotalDistanceSprinted() { this.setTotalDistanceSprinted(0); } /** * Returns a random integer value specifying a sprint length * between 2 and 5 inclusive. */ private int getSprintLength() { return (this.randomNumber.nextInt(4) + 2); } /** * Getter for sporty1. */ public FitnessFrog getSporty1() { return this.sporty1; } /** * Getter for sporty2. */ public FitnessFrog getSporty2() { return this.sporty2; } /** * * * Saves the colour of the receiver, then sets the colour of the * receiver to red and gets a sprint length. Next enters a loop * and on each iteration does the following: First, checks if the * receiver is on the last stone (numbered 11) in which case moves * the receiver to the first stone (numbered 1), otherwise moves * the receiver right; then increments the total distance sprinted. * Upon exit from the loop, casues the receiver to jump once and * then resets its colour. Returns no value. */ public void sprint() { //save colour of the receiver OUColour colour1 = this.getSporty1().getColour(); OUColour colour2 = this.getSporty2().getColour(); //Set colour of receiver to red & get sprint length this.setColour(OUColour.RED); this.getSprintLength(); // if(this.position == 11) { this.home(); } else this.right(); this.setTotalDistanceSprinted(this.getTotalDistanceSprinted()+ getSprintLength() + 1); // Reset receivers colour this.getSporty1().setColour(colour1); this.getSporty2().setColour(colour2); } }
Thanks,
Steven