Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JasperReport ClassCastException

 
Ravi Seth
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


is giving the error: error: net.sf.jasperreports.engine.JasperReport cannot be cast to net.sf.jasperreports.engine.JasperPrint

Please help

 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(Moved to a different forum and changed the topic subject, since the problem seems to have nothing to do with either generating an XLS file, or servlets in general.)
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What type of file are you trying to load on line 9? Is it a jrxml template or a compiled jasper file?
 
Ravi Seth
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Boswell wrote:What type of file are you trying to load on line 9? Is it a jrxml template or a compiled jasper file?


I am trying to load a JRXML or JASPER File and then get a excel file as the output..
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi

I think the exception is caused at this line:The loadObject method is returning a JasperReport object, not JasperPrint.

I think your code needs to be refactored to use a JasperReport object and to compile the jrxml file into a jasper file beforehand.
 
Ravi Seth
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the help, its generating an excel file but the file is empty! does it have anything to do with HashMap in
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap<String, Object>());
If so then how do i populate the file?
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi

You have to point the report at a datasource. This can be in various forms but I am most familiar with those pointing to a database or a bean collection.

There are some samples here:
Jasper Reports Datasources

In terms of your code, once you have the datasource setup, you invoke this version of the fillReport method:
JasperFillManager fillReport(JasperReport, Map, JRDataSource)

Note, you can also use a straight java.sql.Connection object, instead of a JRDataSource if you require it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic