我正在尝试测试 jasperreport 并编写 Java 代码,但它给了我错误:
-------------------- PDF exception
net.sf.jasperreports.engine.JRException:
Error loading byte data : C:\Users\mt\Desktop\project20111116\test
\src3\report2_1336431810533_776931.class
我究竟做错了什么?
代码:
public static void main(String[] args) {
try {
File jrxmlFile = new File("C:\\Users\\mt\\report2.jrxml");
if(jrxmlFile.exists()) {
//jrxml complie
JasperReport jasperReport = JasperCompileManager.compileReport(jrxmlFile.getAbsolutePath());
List<Map<String, ?>> list = new ArrayList<Map<String, ?>>();
for (int i = 0; i < 10; i++) {
Map<String, String> map = new HashMap<String, String>();
map.put("orderNumber", "hello");
map.put("anotherNumber", "world");
//map.put("canIUseArray", new String[]{"foo", "bar", "moo", "pee"});
list.add(map);
}
JRMapCollectionDataSource dataSource = new JRMapCollectionDataSource(list);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap(), dataSource);
JasperViewer.viewReport(jasperPrint, false);
}
}
catch(Exception e) {
System.out.println("-------------------- PDF exception ");
System.out.println(e);
}
System.out.println("DONE");
}//end main