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.
The error message
is due to the fact that
untitled.Toondoes not extenduntitled.Object. It extendsjava.lang.Objectof course, which is why the reason is not immediately obvious from the source code.