4

i've looked through many posts on here and couldn't quite see the solution I need...

I'm getting the error:

the method initTimer(untitled.Object, String, int int) in the type untitled.TimerClass is not applicable for the arguments (untitled.Toon, String, int, int)

and it's driving me crazy.

    timers.initTimer(character, "regenAdd", 0,3);

The above line is the one throwing the error and the following is the function:

public void initTimer(final Object obj, final String method, int delay, int period) {
delay*=1000;
period*=1000;

final Class<?> unknown = obj.getClass();

new Timer().schedule(new TimerTask() {
  public void run() {
    try {
      //get the method from the class 
      Method whatToDo = unknown.getMethod(method, null);
      try {
        //invoke() the object method
        whatToDo.invoke(obj);
      } catch(Exception e) {
        println("Exception encountered: " + e);
      }
    } catch(NoSuchMethodException e) {
      println("Exception encountered: " + e);
    }
    runState = getTimerState();

    if (!runState) {
      println("timer dead");
      this.cancel();
    }
  }
}
, delay, period);
}

Thanks in advance to anybody who can help with this :)

Additional info:

runState is a boolean just incase you couldn't guess and character is an instance of the Toon class; the above method is within the TimerClass class and 'timers' is an instance of that class.

Bohemian
  • 412,405
  • 93
  • 575
  • 722
PsychoMantis
  • 993
  • 2
  • 13
  • 29
  • 1
    `untitled.Object` that's really bad choice for a class name. You should consider renaming it. You are trying to pass `untitled.Toon` where `untitled.Object` is expected. – Bhesh Gurung Dec 15 '12 at 02:12
  • 1
    Can you post the code which is causing the error? Ie the code that calls this method. Show the types of the variables being passed in too – Bohemian Dec 15 '12 at 02:15
  • I've renamed it to `theGame` now so wherever it says `untitled` will now be that. The idea is to pass an unknown object to the function so it can be used for multiple classes. @Bohemian i've posted the code that causes the error and stated the variable types =) – PsychoMantis Dec 15 '12 at 02:24
  • 2
    Does `untitled.Toon` extend `untitled.Object`? – Daniel Fischer Dec 15 '12 at 02:48
  • @DanielFischer Thank you very much good sir, your question has solved my problem! If you post it as an answer I can hit accept in it =) – PsychoMantis Dec 15 '12 at 02:51

2 Answers2

6

The error message

the method initTimer(untitled.Object, String, int int) in the type untitled.TimerClass is not applicable for the arguments (untitled.Toon, String, int, int)

is due to the fact that untitled.Toon does not extend untitled.Object. It extends java.lang.Object of course, which is why the reason is not immediately obvious from the source code.

Daniel Fischer
  • 181,706
  • 17
  • 308
  • 431
-1

Also, another error is initTimer(untitled.Object, String, int) is being called as (untitled.Toon, String, int, int) - notice the difference in number of arguments - 1 int in method declaration and 2 int in calling the method.

Please remember to correct that also.

Lalit
  • 29
  • 6