黑马程序员技术交流社区
标题:
关于报错的问题求解
[打印本页]
作者:
苏伯亚
时间:
2014-4-1 16:15
标题:
关于报错的问题求解
这是代码
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Method applyMethod = GenericTest.class.getMethod("applyVector", Vector.class);
Type [] types=applyMethod.getGenericParameterTypes();
ParameterizedType pType=(ParameterizedType)types[0];
System.out.println(pType.getRawType());
}
private static void applyVector(Vector<Date>v1){
}
总是报这个错误 我异常处理了啊
Exception in thread "main" java.lang.NoSuchMethodException: cn.itcast.day2.GenericTest.applyVector(java.util.Vector)
at java.lang.Class.getMethod(Class.java:1665)
at cn.itcast.day2.GenericTest.main(GenericTest.java:88)//88行就是红字表的
求解答
作者:
霍振鹏
时间:
2014-4-1 17:01
把代码全放上来 看看
作者:
syusikoku
时间:
2014-4-1 17:19
GenericTest.class.getMethod("applyVector", Vector.class)这里出现了问题。建议你更换成
GenericTest.class.getDeclaredMethod("applyVector", Vector.class)来试试。一般默认的只能获取到公共的方法。私有的方法使用getMethod应该是获取不到的。
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2