• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error: The method add(int, int) in the type Main is not applicable for the arguments (int[])  RSS feed

 
kennith stomps
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Making my way a bit farther until yet again I am stuck, I am receiving the error on line 16

The method add(int, int) in the type Main is not applicable for the arguments (int[])

I am passing from line 16 the value of my op array to my add method. Any idea why this error is here?


 
Fred Kleinschmidt
Bartender
Posts: 571
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The add() method has only one signature, one requiring two arguments, each of type int.
You are trying to call it with one argument of type int[]. They are not the same thing.
 
Campbell Ritchie
Marshal
Posts: 56530
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you really been told to write comments with //********* in? Stick to the conventional forms of comment. If those methods are public, they shou‍ld ideally be preceded by /** comments */ so users know how they work. It is a waste of time and not helpful to readers to write comments only saying what is obvious from the code, e.g. // add method immediately preceding public int add(...)
Another formatting thing: look at lines 5‑7; there is no point in having that much empty space inside a method. I would prefer single spacing with single blank lines separating successive methods or other logical parts of the code.
I see you have sorted out the problem about or...or...or 
 
Miguel Callejón
Greenhorn
Posts: 22
4
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change your method signature from:

to

varargs (int...) accept both an array or a list of parameters
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Miguel Callejón wrote:Change your method signature from: ...


That just moves the error downstream -- meaning the add() method will next need to be modified to take an array and not two operands.

Henry
 
Miguel Callejón
Greenhorn
Posts: 22
4
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Miguel Callejón wrote:Change your method signature from: ...


That just moves the error downstream -- meaning the add() method will next need to be modified to take an array and not two operands.

Henry

Yes, you are right, but I thought the OP does not know that if the method accepts two int parameters, it won't accept anything else; but varargs accept both an array and a list of parameters.
 
Campbell Ritchie
Marshal
Posts: 56530
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry is right; if you have written an add(int, int) method, you shou‍ld pass it two ints.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!