本帖最后由 杜光 于 2013-8-4 10:08 编辑
public static void main(String[] args) throws Exception {
InputStream inpt=new FileInputStream("config.properties");
Properties properties = new Properties();
properties.load(inpt);
inpt.close();
String className=properties.getProperty("className");
Collection collection = (Collection) Class.forName(className).newInstance();
// Collection<Object> collection=new HashSet<Object>();
ReflectPoint ref1 = new ReflectPoint(3, 3);
ReflectPoint ref2 = new ReflectPoint(5, 5);
ReflectPoint ref3 = new ReflectPoint(3, 3);
collection.add(ref1);
collection.add(ref2);
collection.add(ref3);
collection.add(ref1);
System.out.println(collection.size());
}
config.properties 配置文件在项目下
是这么写的:
className=java.util.arrayList
运行main函数报错:
Exception in thread "main" java.lang.ClassNotFoundException: java.util.arrayList
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.itcase.day1.ReflectTest2.main(ReflectTest2.java:22)
是什么原因出的错呢?
|