• Post Reply Bookmark Topic Watch Topic
  • New Topic

The method is undefined?  RSS feed

 
Werner Holt
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to run a class with a client code and I get the following error
The method add(TimeSpan) is undefined for the type TEST

Does anyone have an idea why i get this error?







 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a TE‍ST class, it does not have an add method taking a TimeSpan parameter.
Maybe you have an add method with different sorts of parameters. Maybe add is spelt slightly differently.
 
Sai Babu
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Werner,

Did this code compile for you.

In your TimeSpanTEST 's main method

replace add(span) with span.add(span) in the System.out.println
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should use the / and % operators to get minutes to less than 60. Otherwise you can still get 61 minutes. Do you permit time spans with negative values?
 
Werner Holt
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sai Babu wrote:Hey Werner,

Did this code compile for you.

In your TimeSpanTEST 's main method

replace add(span) with span.add(span) in the System.out.println


If I do this I get
 
Werner Holt
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:You should use the / and % operators to get minutes to less than 60. Otherwise you can still get 61 minutes. Do you permit time spans with negative values?

Yes, thank you, I fixed this. Definitely makes more sense.
 
Werner Holt
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So,still anyone has an idea how to fix this?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Werner Holt wrote:
Sai Babu wrote:
replace add(span) with span.add(span) in the System.out.println


If I do this I get


Makes perfect sense. The add() method is a void method. It doesn't return anything. So, there is nothing for the println() method to print. You either have to get rid of the println() call, or have it print something else that can be printed (as a void can't be).

Henry
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!