Cannot cast from Float to String

0
Hi. I have a class with these atributtes.
Code:
/**
 
	 * Constructor for required fields
 
	 */
 
	public BaseAlbaranCuadernosLineas (
 
		java.lang.Integer id,
 
                com.siega.vo.Albarancuadernos idAlbarancuadernos,
 
		java.lang.String concepto,
 
		java.lang.Integer cantidad,
 
                java.lang.Float precio,
 
                java.lang.Float iva,
 
                java.lang.Float importe) {
 
(...)
 
</td></tr></tbody></table>
 
 
 
As you see, I have type Integer, Float and String.
 
 
 
In the .jrxml are the following fields.
 
 
 
<table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"><tbody><tr><td><b>Code:</b></td></tr><tr><td><pre>
 
(...)
 
	<field name="concepto" class="java.lang.String"/>
 
	<field name="cantidad" class="java.lang.Integer"/>
 
	<field name="precio" class="java.lang.Float"/>
 
	<field name="iva" class="java.lang.Float"/>
 
	<field name="importe" class="java.lang.Float"/>
 
(...)
 
</td></tr></tbody></table>
 
 
 
But when I compile the file, show the next error:
 
 
 
net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file: 1. Cannot cast from Float to String                 value = (java.lang.String)(((java.lang.Float)field_iva.getValue()));//$JR_EXPR_ID=12$                         <---------------------------------------------------------> 2. Cannot cast from Float to String  
 
(...)
 
 
 
And when I change the types to String the error show that it´s not good value for the type.
 
 
 
Error evaluating expression : 
 
        Source text : $F{cantidad}
 
 
 
I can´t change the types because I have to do some operations with the values.
 
 
 
Any idea?
 
 
 
Thanks<br>Post edited by: Ajenjo, at: 2008/03/25 18:06
Ajenjo's picture
40
Joined: Mar 13 2008 - 11:50pm
Last seen: 1 year 8 months ago

1 Answer:

0
Ajenjo wrote:
net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file: 1. Cannot cast from Float to String value = (java.lang.String)(((java.lang.Float)field_iva.getValue()));//$JR_EXPR_ID=12$ <---------------------------------------------------------> 2. Cannot cast from Float to String
I assume you have a text field that uses an expression like
Code:
<textFieldExpression>$F{iva}</textFieldExpression>
 
</td></tr></tbody></table>
 
 
 
If this is the case, you will have to change it to
 
<table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"><tbody><tr><td><b>Code:</b></td></tr><tr><td><pre>
 
<textFieldExpression class="java.lang.Float">$F{iva}</textFieldExpression>
 
</td></tr></tbody></table>
 
 
 
If this is not the case, please post your entire JRXML so that we can see where the error comes from.
 
 
 
Regards,
 
Lucian
lucianc's picture
5281
Joined: Jul 17 2006 - 1:10am
Last seen: 3 weeks 3 days ago
Feedback