Reputation: 21
I have tried to run jasper using Struts2 by passing integer parameters to it. But i am getting an error as
cannot assign instance of net.sf.jasperreports.engine.base.JRBaseTextField to field
net.sf.jasperreports.engine.base.JRBaseParagraph.paragraphContainer of type
net.sf.jasperreports.engine.JRParagraphContainer in instance of
net.sf.jasperreports.engine.base.JRBaseParagraph
The code which i used i
parameterMap.put(parametername, param);
connection = dbc.getConnection();
JasperPrint jasperPrint = JasperFillManager.fillReport("jasper.jasper", parameterMap, connection);
JasperExportManager.exportReportToPdfFile(jasperPrint,"jasper.pdf");
Please can any one help me to resolve this problem
Upvotes: 2
Views: 1456
Reputation: 22857
This is known problem as you can see.
Probably you are using commons-digester 2.1
. You should use 1.7
version of commons-digester
library.
UPDATED:
My working sample (standalone maven java application):
public static void testReport() {
Connection connection = null;
try {
Class.forName("org.hsqldb.jdbcDriver");
String url = "jdbc:hsqldb:file:d:\\path_to_db\db_file_name";
connection = DriverManager.getConnection(url, "sa", "");
String reportSource = "d:\\path_to_jrxml\\simple.jrxml";
Map<String, Object> params = new HashMap<String, Object>();
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, connection);
JasperExportManager.exportReportToPdfFile(jasperPrint, "d:\\output_path\\out.pdf");
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
}
The snippet from pom.xml:
<dependencies>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>4.1.2</version>
<exclusions>
<exclusion>
<groupId>tomcat</groupId>
<artifactId>jasper-compiler-jdt</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>groovy</groupId>
<artifactId>groovy-all-1.0-jsr</artifactId>
<version>05</version>
<scope>runtime</scope>
<exclusions>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.2.4</version>
<scope>runtime</scope>
</dependency>
</dependencies>
You can try to build your report with sample application like mine.
I think your issue associated with classpath.
Upvotes: 2