import javax.swing.*;
public class Menu2 {
protected String[] entreeChoice = {"Rosemary Chicken", "Beef Wellington", "Maine Lobster"};
private String menu = "";
private int choice;
protected char initial[] = new char[entreeChoice.length];
public String displayMenu(){
for(int x = 0; x < entreeChoice.length; ++x){
menu = menu + "\n" + (x+1) + "for" + entreeChoice[x];
initial[x] = entreeChoice[x].charAt(0);
}
throws menuException
String input = JOptionPane.showInputDialog(null, "Type your selection, then press Enter." + menu);
choice = Integer.parseInt(input);
return (entreeChoice[choice - 1]);
}
}
我在throws menuException
上遇到錯誤。它說:非法啓動類型。 我幾乎完成了代碼,只是代碼需要修改(附圖),當我這樣做時,我會在代碼的放置位置出錯。修改java代碼錯誤
@Dan想想吧,後者將不起作用,因爲'throw new ...'後面的代碼將變得無法訪問。編輯答案。 – Eran 2014-10-12 11:08:14
現在沒事了。它應該是MenuException,這就是爲什麼我每次都得到錯誤。非常感謝你的幫助 – 2014-10-12 11:13:28