2013-12-08 85 views
0

嗨我正在一個項目上工作,我得到一個我無法解決的錯誤。從Eclipse程序的錯誤信息是:不適用於參數(void)錯誤

Exception in thread "main" java.lang.Error: Unresolved compilation problems: The method add(String) in the type List is not applicable for the arguments (void) The method add(String) in the type List is not applicable for the arguments (void) ham cannot be resolved

at PizzaChoice.main(PizzaChoice.java:50) 

那代碼:

 System.out.print("\nDo you want thick base?"); 
    input = keyboard.nextLine(); 
    choice = input.charAt(0); 
    if (choice == 'y'){ 
     pizza.thick.setCost(8.75); 
     pizza.thick.getType(); 
     l.add(pizza.thick.getType()); 
     c.add((double) pizza.thick.getCost()); 
     totalPizzaBasePrice = totalPizzaBasePrice + pizza.thick.getCost(); 
+3

'pizza.thick.getType()'和'pizza.thick.getCost()'的返回類型是什麼? –

+0

爲什麼你有'pizza.thick.getType();'在自己的線?它應該是'setType()'? – vandale

+0

它在PizzaBase.java – user3077730

回答

0

這個例子可以幫助你看着辦吧,下面ArrayList.add將採取任何對象,但我不因爲表達式new Object().wait()將被評估爲無效(沒有任何內容被等待返回),所以這是編譯器投訴的原因(類型ArrayList中的方法add(Object)不適用於參數(void))

new ArrayList<>().add(new Object().wait()); 

檢查方法pizza.thick.getType()pizza.thick.getCost()的簽名並查看哪些返回空,例如, public void getType().....

1

getType()或getCost()返回類型是void。

相關問題