Class<?> c = Class.forName(prop.getProperty("className"));
Method m = c.getMethod("run");
m.invoke(c);
}
}
复制代码
配置文件
className=practice.Test18
public class DemoClass {
public void run() {
System.out.println("welcome to heima!");
}
}
复制代码
但是总提示我Exception in thread "main" java.lang.NoSuchMethodException: practice.Test18.run()
at java.lang.Class.getMethod(Class.java:1665)
at practice.Test18.main(Test18.java:34)