glassner Posted May 3, 2010 Share Posted May 3, 2010 I am getting the exception below while generating a report from my application (using JasperReports 3.7.1), although with iReports there are no problems. Evidenlty the expression below is flawed. Could you please help me understand why and how to correct it ? Thank you ! $F{academicDegreeType}.equalsIgnoreCase("DOCTORATE") ?($V{TotalACTUAL_DEGREE_QTY}== null ? new BigDecimal("0.0") : $V{TotalACTUAL_DEGREE_QTY}) + $F{actualDegreeQty} :$V{TotalACTUAL_DEGREE_QTY} Code:net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : Source text : $F{academicDegreeType}.equalsIgnoreCase("DOCTORATE") ?($V{TotalACTUAL_DEGREE_QTY}== null ? new BigDecimal("0.0") : $V{TotalACTUAL_DEGREE_QTY}) + $F{actualDegreeQty} :$V{TotalACTUAL_DEGREE_QTY} at net.sf.jasperreports.engine.fill.JREvaluator.evaluateEstimated(JREvaluator.java:253) at net.sf.jasperreports.engine.fill.JRCalculator.evaluateEstimated(JRCalculator.java:561) at net.sf.jasperreports.engine.fill.JRCalculator.estimateVariables(JRCalculator.java:165) at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:784) at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1448) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:108) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:923) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:845) at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:85) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:624) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:605) at mil.af.au.repm.web.action.report.BaseReportAction.generatePdfReport(BaseReportAction.java:66) at mil.af.au.repm.web.action.report.AADQuotaComparisonAction.generateReport(AADQuotaComparisonAction.java:95) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269) at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170) at org.apache.struts.actions.LookupDispatchAction.execute(LookupDispatchAction.java:146) at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58) at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67) at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51) at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190) at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304) at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190) at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462) at javax.servlet.http.HttpServlet.service(HttpServlet.java:763) at javax.servlet.http.HttpServlet.service(HttpServlet.java:856) at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:713) at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370) at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871) at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453) at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:221) at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:122) at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:111) at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260) at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303) at java.lang.Thread.run(Thread.java:595)Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '13' with class 'java.lang.String' to class 'java.lang.Integer' at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:127) at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:256) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:632) at AAD32Quota32Comparison_1272892388946_397215.evaluateEstimated(calculator_AAD32Quota32Comparison_1272892388946_397215:502) at net.sf.jasperreports.engine.fill.JREvaluator.evaluateEstimated(JREvaluator.java:242) Link to comment Share on other sites More sharing options...
keithrbennett Posted June 11, 2010 Share Posted June 11, 2010 I think you need some more parentheses:$F{academicDegreeType}.equalsIgnoreCase("DOCTORATE") ? (($V{TotalACTUAL_DEGREE_QTY} == null ? new BigDecimal("0.0") : $V{TotalACTUAL_DEGREE_QTY}) + $F{actualDegreeQty}) : $V{TotalACTUAL_DEGREE_QTY}With the ternary operator, you need to make sure that it's clear to the compiler that both of the conditional values are unambiguous. Extra parens never hurt:condition ? (true_expr) : (false_expr)- Keith Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now