2013-12-08 110 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。

相关问题