此处不允许使用“void"类型 (java) 错误 [英] 'void' type not allowed here (java) error
本文介绍了此处不允许使用“void"类型 (java) 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
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.");
}
}
我不断收到 'void' type not allowed here
错误.我不想返回任何东西,所以我知道我不需要 int、Boolean、double 等.
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.
我做错了什么?
推荐答案
您的代码不在类中.
试试这个:
public class SomeClass {
// your method here
}
这篇关于此处不允许使用“void"类型 (java) 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文