0

I get the following error message, can anyone see why please?

Error:(21, 38) error: cannot reference colourMatch before supertype constructor has been called

public class Guess {

    Colour[] pegs;
    int correct;
    int colourMatch;


    public Guess(Colour[] pegs, int correct, int colourMatch) {
        //super(pegs);
        this.pegs = pegs.clone();
        this.correct = correct;
        this.colourMatch = colourMatch;
    }

    public Guess(Colour[] currentGuess, Colour[] solution) {
        this(currentGuess, solution, colourMatch);//error message on colourMatch<

    }

    public Colour getPeg(int i) {
        return pegs[i];
    }
}
sheilak
  • 5,573
  • 7
  • 31
  • 38
M.Lewis
  • 15
  • 2
  • 3
    Because you're trying to access the colourMatch **field** (there is no parameter named colourMatch) before the super constructor has been invoked. What exactly don't you understand? – JB Nizet Feb 20 '16 at 16:38
  • what can i do to fix this? – M.Lewis Feb 20 '16 at 17:42
  • What are you trying to achieve? What should be the value of the colourMatch field when you call the second constructor? BTW, you're passing `solution` as the second argument of this(), `solution` is an array of Colour, and the other constructor expects an `int` as second argument. So that doesn't make sense either: a Colour array is not an int. – JB Nizet Feb 20 '16 at 17:44
  • You need to work out what `colourMatch` should be when the second constructor is called. Only you know what that is. – Peter Lawrey Feb 20 '16 at 17:55
  • I'm making a mastermind game app on android studio and in the second constructor every guess should be given feedback in terms of the amount of correctly placed colours as well as the amount of guesses that do occur, but not at the place making sure to only count each combination once, this should use "correct" and "colourMatch" – M.Lewis Feb 20 '16 at 18:07

0 Answers0