简体   繁体   中英

“ '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;
}    

似乎您的raceDice.getSum()返回类型为void。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM