Cannot cast from Float to String

0
Hi.

I have a class with these atributtes.

Code:
<br />
/**<br />
	 * Constructor for required fields<br />
	 */<br />
	public BaseAlbaranCuadernosLineas (<br />
		java.lang.Integer id,<br />
                com.siega.vo.Albarancuadernos idAlbarancuadernos,<br />
		java.lang.String concepto,<br />
		java.lang.Integer cantidad,<br />
                java.lang.Float precio,<br />
                java.lang.Float iva,<br />
                java.lang.Float importe) {<br />
(...)<br />
</td></tr></tbody></table><br />
<br />
As you see, I have type Integer, Float and String.<br />
<br />
In the .jrxml are the following fields.<br />
<br />
<table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"><tbody><tr><td><b>Code:</b></td></tr><tr><td><pre><br />
(...)<br />
	<field name="concepto" class="java.lang.String"/><br />
	<field name="cantidad" class="java.lang.Integer"/><br />
	<field name="precio" class="java.lang.Float"/><br />
	<field name="iva" class="java.lang.Float"/><br />
	<field name="importe" class="java.lang.Float"/><br />
(...)<br />
</td></tr></tbody></table><br />
<br />
But when I compile the file, show the next error:<br />
<br />
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  <br />
(...)<br />
<br />
And when I change the types to String the error show that it´s not good value for the type.<br />
<br />
Error evaluating expression : <br />
        Source text : $F{cantidad}<br />
<br />
I can´t change the types because I have to do some operations with the values.<br />
<br />
Any idea?<br />
<br />
Thanks<br>Post edited by: Ajenjo, at: 2008/03/25 18:06
Ajenjo's picture
30
Joined: Mar 13 2008 - 11:50pm
Last seen: 1 year 6 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:
<br />
<textFieldExpression>$F{iva}</textFieldExpression><br />
</td></tr></tbody></table><br />
<br />
If this is the case, you will have to change it to<br />
<table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"><tbody><tr><td><b>Code:</b></td></tr><tr><td><pre><br />
<textFieldExpression class="java.lang.Float">$F{iva}</textFieldExpression><br />
</td></tr></tbody></table><br />
<br />
If this is not the case, please post your entire JRXML so that we can see where the error comes from.<br />
<br />
Regards,<br />
Lucian
lucianc's picture
5241
Joined: Jul 17 2006 - 1:10am
Last seen: 4 days 12 hours ago
Feedback
randomness