本帖最后由 richard_xiv 于 2012-04-19 21:51:06 编辑

解决方案 »

  1.   

    你的ADD类中是否有add(int,int);方法呢?
      

  2.   


    ADD类里有两个方法
    int add(int x,int y){return x + y;} int dec(int x,int y){ return x - y;}
      

  3.   

    从你的代码来看,你的add函数应该是 static 的吧?这种是类静态函数,要用getDeclaredMethod而不是getMethod成员函数才能用getMethod
      

  4.   

    int add(int x,int y){return x + y;} int dec(int x,int y){ return x - y;}
    你方法的访问权限不是public的,所以getMethod获取不到,看看API上面对方法的介绍吧。使用getDeclaredMethod获取class声明的所有方法,getMethod只能获取为public的方法
      

  5.   


    看了看API,正解。getDeclaredMethod(String name, Class<?>... parameterTypes) 
              Returns a Method object that reflects the specified declared method of the class or interface represented by this Class object.getMethod(String name, Class<?>... parameterTypes) 
              Returns a Method object that reflects the specified public member method of the class or interface represented by this Class object.