明明按照视频写的,为什么没有运行结果
package cn.itcast.day1;
import java.lang.reflect.Method;
public class MethodRegex {
public static void main(String[] args) throws Exception {
String str3 = "abcd";
Method methodCharAt = String.class.getMethod("CharAt", int.class);
System.out.println(methodCharAt.invoke(str3,1));
System.out.println(methodCharAt.invoke(str3, new Object[]{2}));
}
}
Exception in thread "main" java.lang.NoSuchMethodException: java.lang.String.CharAt(int)
at java.lang.Class.getMethod(Class.java:1605)
at cn.itcast.day1.MethodRegex.main(MethodRegex.java:13)
|
|