最近在学ireport,今天在将Chart导出到pdf的时候遇到了问题
我的代码如下:            try
                {
                //生成Chart数据
                ArrayList<ChartBean> data = new ArrayList<ChartBean>(5);
                data.add(new ChartBean("小学", 5));
                data.add(new ChartBean("初中", 10));
                data.add(new ChartBean("高中", 15));
                data.add(new ChartBean("本科", 20));
                data.add(new ChartBean("研究生",15));              JRDataSource dataSource = new JRBeanCollectionDataSource(data);              // 获取报表模板文件
              String root_path = this.getServlet().getServletContext().getRealPath("/");
              root_path = root_path.replace('\\', '/');
              String reportFilePath = root_path + "WEB-INF/classes/com/myapp/ireport/report_2.jasper" ;
              System.out.println( "jasper file is " + reportFilePath);              // 生成JasperPrint
              JasperReport report = (JasperReport)JRLoader.loadObject(reportFilePath);
              JasperPrint jasperPrint = JasperFillManager.fillReport(report, null , dataSource);              // 设定输出格式
              OutputStream ouputStream = response.getOutputStream();
              response.setContentType("application/pdf");
              response.setCharacterEncoding( "GB2312" );
              response.setHeader("Content-Disposition" , "attachment;filename="
                      + URLEncoder.encode("PDF报表" , "GB2312") + ".pdf");//              // 使用JRPdfExproter导出器导出pdf
              JRPdfExporter exporter = new JRPdfExporter();
//              // 设置JasperPrintList
              exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
              exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
              exporter.exportReport();
              ouputStream.close();我使用的Bean数据源
Bean为:public class ChartBean {
    private String degree;
    private Integer count;    public ChartBean(String degree, Integer count) {
        this.degree = degree;
        this.count = count;
    }    public ChartBean() {
    }    public Integer getCount() {
        return count;
    }    public void setCount(Integer count) {
        this.count = count;
    }    public String getDegree() {
        return degree;
    }    public void setDegree(String degree) {
        this.degree = degree;
    }使用这段代码导出一般报表时没有问题,可是导出pie 3d chart时却出现了Null 'key' argument问题。
提示是JasperPrint jasperPrint = JasperFillManager.fillReport(report, null , dataSource);这行有问题。
我一开始以为有可能是我传的null出了问题。于是我给jrxml中添加了一个paramter,建了一个map传了过去,可是照样报同样的错误。
于是我上网找了找,发现有可能是我传的数据data中含有NULL值。试了试,发现ArrayList默认初始length为10,不足10个的数据都为NULL。于是我改为ArrayList<ChartBean> data = new ArrayList<ChartBean>(5);
再调试,data中没有null了。
再运行,同样是Null 'key' argument
我是彻底的无语了,实在找不出是哪里出了错,有没有遇到和我同样问题的朋友啊?
请知道的高手为我解答,谢谢。