Duarte Saraiva
Duarte Saraiva

Reputation: 31

" 'void' type not allowed here " Error message

public void runTheHorses()
{
    for (int i=0; i < 4; i++) {
        if (!gameOver) {        
            raceDice.rollDice();
            if (horses[i].getMovingNumber() < raceDice.getSum()) {
                horses[i].updatePosition(raceDice.getDifference());
                if (horses[i].getPosition() >= finishLine) {
                    gameOver=true; 
                    winner=horses[i].getName();
                }
            }
            horses[i].setMovingNumber();
        }
    }
} // end method    

I am making a horse race program. It is just a simple school exercise but when I try to compile it gives me an error message. In the line:

if (horses[i].getMovingNumber**()** < raceDice.getSum()){    

Where it is bold, (the brackets after .getMovingNumber), it gives me the " 'void' type not allowed here" error message. I do not know what to do. The original method for getMovingNumber is:

private int movingNumber=4;

public int getMovingNumber()
{
    return movingNumber;
}    

Upvotes: 0

Views: 826

Answers (1)

Maksym
Maksym

Reputation: 4574

Seems like your raceDice.getSum() return type is void.

Upvotes: 3

Related Questions