本帖最后由 yangjie 于 2013-9-28 20:06 编辑
自己打高新技术56里的代码的时候,出了个错怎么也搞不懂。
放上来请大家看看,求解释
=================================================================
已解决。xxx.advice = Adivce←单词打错了。之前还特地检查过好几遍拼写都没发现,OTZ
- <P>
- import java.io.*;
- import java.util.*;
- import java.lang.reflect.*;
- public class Test
- {
- public static void main(String[] args) throws Exception
- {
- //读取配置文件内容
- String name = "xxx";
- Properties prop = new Properties();;
- prop.load(new FileInputStream("properties"));
- //通过读取到的字符串建立对象
- Object target = Class.forName(prop.getProperty(name + ".target")).newInstance();
- Advice advice = (Advice)Class.forName("Advice").newInstance();//这句运行成功
- //Advice advice = (Advice)Class.forName(prop.getProperty(name + ".advice")).newInstance();//这句运行就是ClassNotFoundException
- System.out.println(prop.getProperty(name + ".advice"));//把读到的值打出来看看,是Advice没错
- System.out.println("---"+target.getClass().getName());
- System.out.println("---"+advice.getClass().getName());
- }
- }
复制代码 properties中的内容
#xxx = java.util.ArrayList
xxx = ProxyBeanFactory
xxx.target = java.util.TreeSet
xxx.advice = Adivce
|