9

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");
Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
Dee
  • 483
  • 2
  • 11
  • 24
  • I'd also have a look at using a unit testing framework, such as [junit](http://junit.org/) or [testng](http://testng.org/doc/index.html) for writing your tests, so that you have much more manageable testing than what you have with your humongous `main()` method approach. – Edd Apr 02 '14 at 13:57

2 Answers2

14

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.)

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • 3
    @Ammu: It's worth taking a step back and working out why you couldn't figure it out from the compiler error message. Did you not know where to look? Did you not understand the message? Basically, try to learn from this experience so you can fix it yourself next time. – Jon Skeet Apr 02 '14 at 14:19
1

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?

Community
  • 1
  • 1
Jayanth
  • 329
  • 4
  • 15