2002 JI Open Discussion Posted August 18, 2006 Share Posted August 18, 2006 By: Gary Hill - gary_hill94 Variables and Arithmetic 2003-08-14 20:54 I have two variables of type Double that are sums of two fields of type Double. I would like to assign the difference of these two variables to a third variable, of type double, to print in a group footer. I get an invalid cast error from the report compiler when I do this. Here are the lines from my report definition: <variable name="balance" class="java.lang.Double" resetType="None" calculation="Nothing"> <variableExpression>$V{gross} - $V{receipts}</variableExpression> </variable> Here are the errors: dori.jasper.engine.JRException: Errors were encountered when compiling report design: /home/ghill/office/JasperReports/ArDetail.java:232: Invalid cast from int to java.lang.Double. value = (java.lang.Double)(((java.lang.Double)variable_gross.getValue()) - ((java.lang.Double)variable_receipts.getValue())); ^ /home/ghill/office/JasperReports/ArDetail.java:232: Incompatible type for -. Can't convert java.lang.Double to int. value = (java.lang.Double)(((java.lang.Double)variable_gross.getValue()) - ((java.lang.Double)variable_receipts.getValue())); ^ /home/ghill/office/JasperReports/ArDetail.java:445: Invalid cast from int to java.lang.Double. value = (java.lang.Double)(((java.lang.Double)variable_gross.getOldValue()) - ((java.lang.Double)variable_receipts.getOldValue())); ^ /home/ghill/office/JasperReports/ArDetail.java:445: Incompatible type for -. Can't convert java.lang.Double to int. value = (java.lang.Double)(((java.lang.Double)variable_gross.getOldValue()) - ((java.lang.Double)variable_receipts.getOldValue())); ^ /home/ghill/office/JasperReports/ArDetail.java:658: Invalid cast from int to java.lang.Double. value = (java.lang.Double)(((java.lang.Double)variable_gross.getEstimatedValue()) - ((java.lang.Double)variable_receipts.getEstimatedValue())); ^ /home/ghill/office/JasperReports/ArDetail.java:658: Incompatible type for -. Can't convert java.lang.Double to int. value = (java.lang.Double)(((java.lang.Double)variable_gross.getEstimatedValue()) - ((java.lang.Double)variable_receipts.getEstimatedValue())); ^ 6 errors By: Teodor Danciu - teodord RE: Variables and Arithmetic 2003-08-14 23:47 Hi, Here's the correct expression : <variableExpression> new Double( $V{gross}.doubleValue() - $V{receipts}.doubleValue() ) </variableExpression> You might also consider testing the "gross" and "receipt" variable for null in the expression using the ?: java operator. I hope this helps. Teodor 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