在執行下面的類時,將拋出「線程'main'java.lang.NoClassDefFoundError」中的異常。我預計這個例外將被拋出爲「MainMethodNotFoundException」。線程「main」中的異常java.lang.NoClassDefFoundError而不是MainMethodNotFound
爲什麼noClassDefFoundError在這裏被拋出?
public class TestingSwitch {
public static void main(String args) {
int cnt = 1;
switch(cnt){
default:
System.out.println("Welcome");
case 1:
System.out.println("One");
break;
case 2:
System.out.println("Two");
break;
}
}
}
你是怎麼執行的這個代碼?你能告訴我們你用來執行java的命令嗎? – jfcorugedo
夥計 我很確定主要方法簽名是錯誤的。 但我期待的答案是:爲什麼「NoClassDefFoundError」而不是MainMethodNotFound? –
是的,我明白了。但它取決於你用來執行類的命令。你確定你在控制檯中鍵入的類是否存在並被編譯? – jfcorugedo