Method in type not applicable to arguments

I looked through a lot of posts here and could not see the solution I needed ...

I get an 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) 

and it drives me crazy.

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

The above line is the one that throws the error, and the following 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 anyone who can help with this :)

Additional Information:

runState is a logical expression that you could not guess and a character is an instance of the Toon class; the above method is within the class TimerClass and the "timers" are an instance of this class.

+4
source share
2 answers

Error message

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

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

+6
source

In addition, another error - initTimer (untitled.Object, String, int) is called as (untitled.Toon, String, int, int) - notices the difference in the number of arguments - 1 int in the method declaration and 2 int when the method is called.

Remember to also fix this.

-1
source

All Articles