- public class Test {
-
- public static void main(String[] args) {
- try {
- Object obj = ReflectPiont.class.newInstance();
- Method method = obj.getClass().getMethod("printStr",String.class);
- String str = "aaa";
- method.invoke(null,str);
-
- System.out.println("aaa");
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
- }
- class ReflectPiont{
-
- private static void printStr(String str) {
- // TODO Auto-generated method stub
- System.out.println(str);
- }
- }
复制代码 java.lang.NoSuchMethodException: com.itheima.ReflectPiont.printStr(java.lang.String)
at java.lang.Class.getMethod(Unknown Source)
at com.itheima.Test7.main(Test7.java:14)
这是怎么出错的
|
|