This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes JasperReport ClassCastException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "JasperReport ClassCastException" Watch "JasperReport ClassCastException" New topic
Author

JasperReport ClassCastException

Ravi Seth
Greenhorn

Joined: Apr 30, 2013
Posts: 5


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

Please help

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41149
    
  45
(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.)


Ping & DNS - my free Android networking tools app
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

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

Joined: Apr 30, 2013
Posts: 5
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

Joined: Nov 09, 2011
Posts: 1012
    
    5

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

Joined: Apr 30, 2013
Posts: 5
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

Joined: Nov 09, 2011
Posts: 1012
    
    5

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JasperReport ClassCastException
 
Similar Threads
download files with scandic letters
java.lang.IllegalStateException:- when generating excel report
simple jasper report in java without a database.
Issue with jasper reports export
Storing multiple query string and execute them using result set