在类型方法是不适用的论点 [英] Method in the type is not applicable to the arguments

查看:155
本文介绍了在类型方法是不适用的论点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过很多帖子在这里看着,并不能完全看到的解决方案,我需要...

我收到以下错误:

 方法initTimer(untitled.Object,字符串,整数INT)在类型untitled.TimerClass不适用于参数(untitled.Toon,字符串,INT,INT)

和它的驾驶我疯了。

  timers.initTimer(字符,regenAdd,0,3);

上面的线是一个引发错误和以下的功能是:

 公共无效initTimer(最终obj对象,最后字符串的方法,诠释延迟,诠释时间){
延迟* = 1000;
期间* = 1000;最后一类<>未知= obj.getClass();新的Timer()。时间表(新的TimerTask(){
  公共无效的run(){
    尝试{
      //从类中的方法
      方法whatToDo = unknown.getMethod(方法,NULL);
      尝试{
        //调用()的对象方法
        whatToDo.invoke(OBJ);
      }赶上(例外五){
        的println(异常遭遇:+ E);
      }
    }赶上(NoSuchMethodException E){
      的println(异常遭遇:+ E);
    }
    runState = getTimerState();    如果(!runState){
      的println(定时器死);
      this.cancel();
    }
  }
}
,延迟期);
}

在此先感谢任何人谁可以帮助这一点:)

附加信息:


  

runState是一个布尔只是柜面你猜不透和
  字符是卡通类的一个实例;上述方法中
  在TimerClass类和计时器是类的一个实例。



解决方案

错误消息


  

该方法 initTimer(untitled.Object,字符串,整数INT)中的类型 untitled.TimerClass 不是
  适用于参数(untitled.Toon,字符串,INT,INT)


是由于这一事实,即 untitled.Toon 不延长 untitled.Object 。它扩展了的java.lang.Object 当然,这也是为什么其原因是没有从源头code显而易见的。

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

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.

这篇关于在类型方法是不适用的论点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆