代码:
` try {
seleniumBase sb = (seleniumBase)Class.forName("com.github.wycm.API._douban")
.newInstance();
System.out.println(sb);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| SecurityException | ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}`
报错:
` java.lang.InstantiationException: com.github.wycm.API._douban
at java.base/java.lang.Class.newInstance(Class.java:598)
at model.function.reflectUtil.main(reflectUtil.java:32)
Caused by: java.lang.NoSuchMethodException: com.github.wycm.API._douban.<init>()
at java.base/java.lang.Class.getConstructor0(Class.java:3427)
at java.base/java.lang.Class.newInstance(Class.java:585)
... 1 more`
- *更新报错:eclipse main函数内运行,反射成功。
而启动Tomcat后调用,反射失败。这怎么回事?
java.lang.ClassNotFoundException: com.github.wycm.API._douban at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1365) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188) at java.base/java.lang.Class.forName0(Native Method) at java.base/java.lang.Class.forName(Class.java:340) at model.API.base.APIBase.executeSeleniumByReflectUtil(APIBase.java:2395)