java自动适应类型的参数_java – 类型中的方法不适用于参数

我在这里查看过很多帖子,看不出我需要的解决方案……

我收到错误:

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

这让我发疯了.

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

以上行是抛出错误的行,以下是函数:

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);

}

在此先感谢任何可以帮助的人:)

附加信息:

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值