Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Error - Actual and formal argument lists differ in length

Tags:

java

I am trying to call a method, but it is giving this error:

java:112: error: required: String, String

found: String

reason: actual and formal arguments lists differ in length

Here is the method I'm trying to call:

public void setShippingDest(String inCustName, String inDestn) {
    // ...
}

Here is how I'm trying to call it:

shipOrder.setShippingDest("Broome");
like image 989
Dee Avatar asked Apr 02 '14 13:04

Dee


2 Answers

Well it's quite simple. Here's the declaration of setShippingDest:

public void setShippingDest(String inCustName, String inDestn)

And here's how you're trying to call it:

shipOrder.setShippingDest("Broome");

You've provided one argument, but there are two parameters? How do you expect that to work? You either need to provide another argument, or remove one parameter.

(I'd also strongly advise that you remove the in prefix from all of your parameters, and look into a real unit testing framework such as JUnit, rather than writing an enormous main method.)

like image 145
Jon Skeet Avatar answered Oct 18 '22 08:10

Jon Skeet


Also if you like to specify only the Customer Name, you could do so by overloading the method as

    public void setShippingDest(String inCustName)
    {
      return  setShippingDest(inCustName, defaultvalue1);
    }

See how to set default method argument values?

like image 29
Jayanth Avatar answered Oct 18 '22 08:10

Jayanth