小弟刚接触castor,想测试一下简单的编组/解组,结果测试的时候报出了 ClassDescriptorResolver from context must not be null!{File: [not available]; line: 2; column: 568}错误。
编组生成的xml文件正常,但是把生成的xml数据文件再解组输出的时候就出错了,有大神给指导一下么?谢谢了。
附主要的代码:
                     Mapping map = new Mapping();
map.loadMapping("allMapping.xml"); File file = new File("testMapping_all.xml");
Writer writer = new FileWriter(file);
Marshaller marshaller = new Marshaller(writer);
marshaller.setMapping(map);
marshaller.marshal(timeTableBean); // now restore the value and list what we get
Reader reader = new FileReader(file);
Unmarshaller unmarshaller = new Unmarshaller(map);
TimeTableBean read = (TimeTableBean)unmarshaller.unmarshal(reader);//这里出错

解决方案 »

  1.   

    xml用浏览器打开看看有错没。
      

  2.   

    没有错
      <?xml version="1.0" encoding="UTF-8" ?> 
    - <timetable>
    - <carrier identy="BOYIN">
      <carrier-name>波音747</carrier-name> 
      <carrier-type>民航</carrier-type> 
      </carrier>
    - <carrier identy="KONGKE">
      <carrier-name>空客A919</carrier-name> 
      <carrier-type>国航</carrier-type> 
      </carrier>
    - <airport identy="BJ">
      <airport-place>首都机场</airport-place> 
      <airport-name>北京</airport-name> 
      </airport>
    - <airport identy="QD">
      <airport-place>流亭机场</airport-place> 
      <airport-name>青岛</airport-name> 
      </airport>
    - <route from="BJ" to="QD">
      <flight carrier="BOYIN" depart="6:23a" arrive="8:42a" number="119" /> 
      <flight carrier="KONGKE" depart="7:23a" arrive="9:42a" number="120" /> 
      </route>
      </timetable>
    这是在浏览器打开的效果
      

  3.   

    还有别的方法没呢???%>_<%
      

  4.   

    有中文用这个试试InputStreamReader(new InputStream(file), "UTF-8")
      

  5.   

    ClassDescriptorResolver from context must not be null!{File: [not available]; line: 2; column: 568}lz仔细检查下
      

  6.   

    这句话不能用啊,是这么写的么?是不是应该是 Class xxx = InputStreamReader(new InputStream(file), "UTF-8");类似的这种形式啊??
      

  7.   

    java.io.Reader reader = new InputStreamReader(new FileInputStream(file), "UTF-8");
      

  8.   

    NND 你XML明显多了个</carrier>
      

  9.   

    我说错了,你xml的编码要和读时候的编码一致。子看看文件编码。
      

  10.   

    XML的编码是UTF-8的,上面已经列出来了,读的时候的编码也是UTF-8的,用的你的那个方法啊,这不是一样的么?
      

  11.   

    我说的文件本身,用记事本打开另存为utf-8
      

  12.   

    还是不行呢,我把映射文件另存为UTF-8的格式,然后又考进来了,还是那个错误,大神继续关注啊,谢了。
      

  13.   

    我已经无语了,你把你相关问题代码上传资源,给我个url,回家我看看。
      

  14.   

    http://download.csdn.net/source/3514591上传上去了,先谢过啦