Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

JasperReport ClassCastException

 
Greenhorn
Posts: 6
  • 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

 
Rancher
Posts: 43011
76
  • 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.)
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • 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: 6
  • 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
Hibernate Eclipse IDE Chrome
  • 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: 6
  • 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
Hibernate Eclipse IDE Chrome
  • 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.
 
On top of spaghetti all covered in cheese, there was this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!