Reputation: 3
Hi I am working on a project and i get an error which I cant solve. The error message from the Eclipse program is:
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)
Thats the code:
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();
Upvotes: 0
Views: 2722
Reputation: 2068
This example will help you figure it out, ArrayList.add
below would take any object but I'm not passing it anything since the expression new Object().wait()
will evaluate to void (nothing is returned by wait), that is why the compiler complaints (The method add(Object) in the type ArrayList is not applicable for the arguments (void))
new ArrayList<>().add(new Object().wait());
check the signature of the methods pizza.thick.getType()
and pizza.thick.getCost()
and see which returns void e.g. public void getType().....
Upvotes: 0