问题
Here is my code:
public void start()
{
//If the gas tank and oil have more than nothing, and the transmission is in gear park, then the car can start
if((gasTank.getGasLevel() > 0) && (engine.getOilLevel() > 0) && (transmission.gearPark()))
{
engine.startEngine();
System.out.println("Engine is now on");
}
else
{
System.out.println("Please make sure your car is in proper gear, engine has oil and gas.");
}
}
I keep getting 'void' type not allowed here
error. I am not trying to return anything so I know I don't need int, Boolean, double, etc.
What am I doing wrong?
回答1:
Your code is not inside a class.
Try this:
public class SomeClass {
// your method here
}
回答2:
It looks like one or more of these methods might be void, but must not be:
getGasLevel();
getOilLevel();
gearPark()
They must not be void because you are checking values returned from them in the if statement.
来源:https://stackoverflow.com/questions/15019723/void-type-not-allowed-here-java-error