我想在NetBeans中運行一些Java代碼,它一直告訴我沒有主類。我已經看過其他類似的問題,但他們不幫助解決我的特定問題。如何解決「<找不到主要課程>」?
即使我添加主循環,它仍然告訴我沒有主類。此代碼的目的是創建一個名爲VolcanoRobot的類,該類可以在另一個程序中使用,或者我可以添加public static void main(String args[])
並運行此代碼。
嘗試這兩種方法編譯器仍然有這個相同的問題。這裏是我的代碼有使用類:
class VolcanoApplication {
public static void main(String[] args){
VolcanoRobot dante = new VolcanoRobot();
dante.status = "exploring";
dante.speed = 2;
dante.temperature = 510;
dante.showAttributes();
System.out.println("Increasing speed to 3.");
dante.speed = 3;
dante.showAttributes();
System.out.println("Changing temperature to 670.");
dante.temperature = 670;
dante.showAttributes();
System.out.println("Checking the temparature");
dante.checkTemperature();
dante.showAttributes();
}}
VolcanoRobot的創作:
class VolcanoRobot {
String status;
int speed;
float temperature;
void checkTemperature() {
if (temperature > 600) {
status = "returning home";
speed = 5;
}
}
void showAttributes() {
System.out.println("Status: " + status);
System.out.println("Speed: " + speed);
System.out.println("Temperature: " + temperature);
}
}
你有其他類或這都是你的代碼? - 事實上你需要有一個包含主要方法的公共類。如果你沒有,那麼這就是問題所在。 – Leah
你如何運行你的項目? – JeredM
我正在使用NetBeans運行它。 –