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


我正在制作赛马程序。这只是一个简单的学校练习,但是当我尝试编译它时,会给我一个错误消息。在该行中:

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


在粗体字(.getMovingNumber之后的括号)的地方,它给我“此处不允许的'void'类型”错误消息。我不知道该怎么办。 getMovingNumber的原始方法是:

private int movingNumber=4;

public int getMovingNumber()
{
    return movingNumber;
}

最佳答案

看来您的raceDice.getSum()返回类型为void。

关于java - “这里不允许'void'类型”错误信息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26889560/

10-11 04:36