Class Cast exception: Jasper fails to thrill me

0

It's hard to be optimistic after 3 days of fiddling with Jasper and IReport. Nonetheless I will describe my latest issue:

I get a Class Cast exception when retrieving a custom data source at the subreport level. And knowing there is no effective means to understand what's going on under the covers (since this tool is very deficient in providing such means to developers) I decided to do an experiment.

I wanted to determine what was in the REPORT_DATA_SOURCE property at the top of the master report.

So I setup a property to retrieve a value that I assumed to be my custom data source. (For my connection setup had already tested OK with my custom datasource "com.catalystwms.cct.web.beans.reports.TestDataSource")

But when I run this snippet of code in my report, out pops the Class cast exception. Why? Why doesn't this work? (All files are attached.)






IReport TRACE
==============
ÂTime zone: default
ErrorÂfillingÂprint...
ENTEREDÂTestDataSourceFactory.getTheDatasource() ENTEREDÂTestDataSource()ÂCONSTRUCTOR ENTEREDÂaddRowÂindex=0 ENTEREDÂTestDataSource(List)ÂCONSTRUCTOR ENTEREDÂTestDataSource.putSubDataSourceFromRow()Âkey=Tasks ENTEREDÂaddRowÂindex=1 ENTEREDÂTestDataSource(List)ÂCONSTRUCTOR ENTEREDÂTestDataSource.putSubDataSourceFromRow()Âkey=Tasks java.lang.ClassCastException:Âcom.catalystwms.cct.web.beans.reports.TestDataSource ÂÂÂÂatÂTestDataSource_1154553627259_783159.evaluate(TestDataSource_1154553627259_783159:126) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:172) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:539) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:507) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRFillDataset.setFillParameterValues(JRFillDataset.java:631) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRFillDataset.setParameterValues(JRFillDataset.java:593) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRBaseFiller.setParameters(JRBaseFiller.java:879) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:708) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:685) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89) ÂÂÂÂatÂnet.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601) ÂÂÂÂatÂit.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:728) ÂÂÂÂatÂjava.lang.Thread.run(UnknownÂSource) NESTEDÂBYÂ: java.lang.ClassCastException:Âcom.catalystwms.cct.web.beans.reports.TestDataSource ÂÂÂÂatÂTestDataSource_1154553627259_783159.evaluate(TestDataSource_1154553627259_783159:126) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:172) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:539) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:507) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRFillDataset.setFillParameterValues(JRFillDataset.java:631) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRFillDataset.setParameterValues(JRFillDataset.java:593) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRBaseFiller.setParameters(JRBaseFiller.java:879) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:708) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:685) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89) ÂÂÂÂatÂnet.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601) ÂÂÂÂatÂit.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:728) ÂÂÂÂatÂjava.lang.Thread.run(UnknownÂSource) NESTEDÂBYÂ: net.sf.jasperreports.engine.fill.JRExpressionEvalException:ÂErrorÂevaluatingÂexpressionÂ:Â ÂÂÂÂSourceÂtextÂ:Â((com.catalystwms.cct.web.beans.reports.TestDataSource)$P{REPORT_DATA_SOURCE}) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:183) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:539) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:507) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRFillDataset.setFillParameterValues(JRFillDataset.java:631) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRFillDataset.setParameterValues(JRFillDataset.java:593) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRBaseFiller.setParameters(JRBaseFiller.java:879) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:708) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:685) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:89) ÂÂÂÂatÂnet.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601) ÂÂÂÂatÂit.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:728) ÂÂÂÂatÂjava.lang.Thread.run(UnknownÂSource) CausedÂby:Âjava.lang.ClassCastException:Âcom.catalystwms.cct.web.beans.reports.TestDataSource ÂÂÂÂatÂTestDataSource_1154553627259_783159.evaluate(TestDataSource_1154553627259_783159:126) ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:172) ÂÂÂÂ...Â11Âmore
PrintÂnotÂfilled.ÂTryÂtoÂuseÂanÂEmptyDataSource...!

kjhuebner's picture
Joined: Jul 31 2006 - 3:01am
Last seen: 15 years 5 months ago

3 Answers:

0
Files:
[file name=TestDataSource-a8b3d704fe7c9f10704a34bc6adbaf36.zip size=23342]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/Tes...
kjhuebner's picture
Joined: Jul 31 2006 - 3:01am
Last seen: 15 years 5 months ago
0
I ran into a similar problem when using JavaBean datasource with subreports. Try wrapping your subreport beans into a JRBeanCollectionDataSource and pass that back. Worked for me.
ronjc's picture
1
Joined: May 17 2007 - 12:48am
Last seen: 14 years 8 months ago
0
Change your expression to create a new object of type TestDataSource like this:


<defaultValueExpression ><![CDATA[new com.catalystwms.cct.web.beans.reports.TestDataSource($P{REPORT_DATA_SOURCE})]]></ defaultValueExpression>
jmurray's picture
575
Joined: Dec 11 2006 - 11:19am
Last seen: 15 years 1 month ago
Feedback
randomness