I have some problems with JasperReport. I’ve generated a *.jrxml File through iReport.
There I’ve definded some fields. Now i want to set these fields in my Java-Application, but it didn’t work.
My Code looks like
JasperReport report;
JasperPrint print;
HashMap<String, Object> parameters = new HashMap<String, Object>();
parameters.put("logoPath", "\\logo.jpg");
parameters.put("companyName", "Company Name");
try {
report = JasperCompileManager
.compileReport("JRXML\\Template.jrxml");
for (JRField field : report.getFields()) {
System.out.println(field.getName() + "|"
+ field.getValueClassName());
}
print = JasperFillManager.fillReport(report, parameters,
new JREmptyDataSource());
JasperExportManager.exportReportToPdfFile(print,
"\\temp\\Example.pdf");
JasperViewer.viewReport(print);
} catch (Exception e) {
// TODO Auto-generated catch block
Logger.getLogger(Example1.class.getName()).log(Level.ALL,
e.getLocalizedMessage());
e.printStackTrace();
}
The fields are given in the *.jrxml file.
Thanks for your help
You are confusing parameters with fields. A paramater is defined as
<parameter name="companyName" class="java.lang.String" isForPrompting="false">, while a field is defined as<field name="companyName" class="java.lang.String"/>. Convert company name to parameter in your jrxml and it should work.From this tutorial
ORIGINAL ANSWER:
Use a FileResolver for logo.jpg, which Jasper will use to resolve files locations.