Jump to content
Changes to the Jaspersoft community edition download ×

problem with casting


patrick24

Recommended Posts

Hi,

I try to report database values wiht hibernate. but I recive falloving error :


net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. Cannot cast from Date to String
                value = (java.lang.String)(((java.util.Date)field_datum.getValue())); //$JR_EXPR_ID=10$
                        <---------------------------------------------------------->
2. Cannot cast from Float to String
                value = (java.lang.String)(((java.lang.Float)field_netto.getValue())); //$JR_EXPR_ID=11$
                        <----------------------------------------------------------->
3. Cannot cast from Float to String
                value = (java.lang.String)(((java.lang.Float)field_mwst.getValue())); //$JR_EXPR_ID=12$
                        <---------------------------------------------------------->
4. Cannot cast from Integer to String
                value = (java.lang.String)(((java.lang.Integer)field_rabatt.getValue())); //$JR_EXPR_ID=13$
                        <-------------------------------------------------------------->
5. Cannot cast from Integer to String
                value = (java.lang.String)(((java.lang.Integer)field_zbid.getValue())); //$JR_EXPR_ID=14$
                        <------------------------------------------------------------>
6. Cannot cast from Integer to String
                value = (java.lang.String)(((java.lang.Integer)field_ausgewaehlt.getValue())); //$JR_EXPR_ID=16$
                        <------------------------------------------------------------------->
7. Cannot cast from Float to String
                value = (java.lang.String)(((java.lang.Float)field_bezahlt.getValue())); //$JR_EXPR_ID=17$
                        <------------------------------------------------------------->
8. Cannot cast from Date to String
                value = (java.lang.String)(((java.util.Date)field_datum.getOldValue())); //$JR_EXPR_ID=10$
                        <------------------------------------------------------------->
9. Cannot cast from Float to String
                value = (java.lang.String)(((java.lang.Float)field_netto.getOldValue())); //$JR_EXPR_ID=11$
                        <-------------------------------------------------------------->
10. Cannot cast from Float to String
                value = (java.lang.String)(((java.lang.Float)field_mwst.getOldValue())); //$JR_EXPR_ID=12$
                        <------------------------------------------------------------->
11. Cannot cast from Integer to String
                value = (java.lang.String)(((java.lang.Integer)field_rabatt.getOldValue())); //$JR_EXPR_ID=13$
                        <----------------------------------------------------------------->
12. Cannot cast from Integer to String
                value = (java.lang.String)(((java.lang.Integer)field_zbid.getOldValue())); //$JR_EXPR_ID=14$
                        <--------------------------------------------------------------->
13. Cannot cast from Integer to String
                value = (java.lang.String)(((java.lang.Integer)field_ausgewaehlt.getOldValue())); //$JR_EXPR_ID=16$
                        <---------------------------------------------------------------------->
14. Cannot cast from Float to String
                value = (java.lang.String)(((java.lang.Float)field_bezahlt.getOldValue())); //$JR_EXPR_ID=17$
                        <---------------------------------------------------------------->
15. Cannot cast from Date to String
                value = (java.lang.String)(((java.util.Date)field_datum.getValue())); //$JR_EXPR_ID=10$
                        <---------------------------------------------------------->
16. Cannot cast from Float to String
                value = (java.lang.String)(((java.lang.Float)field_netto.getValue())); //$JR_EXPR_ID=11$
                        <----------------------------------------------------------->
17. Cannot cast from Float to String
                value = (java.lang.String)(((java.lang.Float)field_mwst.getValue())); //$JR_EXPR_ID=12$
                        <---------------------------------------------------------->
18. Cannot cast from Integer to String
                value = (java.lang.String)(((java.lang.Integer)field_rabatt.getValue())); //$JR_EXPR_ID=13$
                        <-------------------------------------------------------------->
19. Cannot cast from Integer to String
                value = (java.lang.String)(((java.lang.Integer)field_zbid.getValue())); //$JR_EXPR_ID=14$
                        <------------------------------------------------------------>
20. Cannot cast from Integer to String
                value = (java.lang.String)(((java.lang.Integer)field_ausgewaehlt.getValue())); //$JR_EXPR_ID=16$
                        <------------------------------------------------------------------->
21. Cannot cast from Float to String
                value = (java.lang.String)(((java.lang.Float)field_bezahlt.getValue())); //$JR_EXPR_ID=17$
                        <------------------------------------------------------------->

what is wrong?

 

Code:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd"><jasperReport name="Handwerk2008BelegReport">		<queryString language="hql">		<![CDATA[from Beleg]]>	</queryString>	<field name="belegid" class="java.lang.String"/>	<field name="adressid" class="java.lang.String"/>	<field name="datum" class="java.util.Date"/>	<field name="netto" class="java.lang.Float"/>	<field name="mwst" class="java.lang.Float"/>	<field name="rabatt" class="java.lang.Integer"/>	<field name="zbid" class="java.lang.Integer"/>	<field name="bemerkung" class="java.lang.String"/>	<field name="ausgewaehlt" class="java.lang.Integer"/>	<field name="bezahlt" class="java.lang.Float"/>	<field name="oztyp" class="java.lang.String"/>	<field name="status" class="java.lang.Integer"/>		<title>		<band height="30">			<staticText>				<reportElement width="555" y="0" x="0" height="30"></reportElement>				<text>					<![CDATA["BelegReport"]]>				</text>			</staticText>		</band>	</title>	<pageHeader>		<band height="30">			<staticText>				<reportElement width="100" y="0" x="0" height="30"></reportElement>				<text>![CDATA[belegid]]</text>			</staticText>			<staticText>				<reportElement width="100" y="0" x="0" height="30"></reportElement>				<text>![CDATA[adressid]]</text>			</staticText>			<staticText>				<reportElement width="100" y="0" x="0" height="30"></reportElement>				<text>![CDATA[datum]]</text>			</staticText>			<staticText>				<reportElement width="100" y="0" x="0" height="30"></reportElement>				<text>![CDATA[netto]]</text>			</staticText>			<staticText>				<reportElement width="100" y="0" x="0" height="30"></reportElement>				<text>![CDATA[mwst]]</text>			</staticText>			<staticText>				<reportElement width="100" y="0" x="0" height="30"></reportElement>				<text>![CDATA[rabatt]]</text>			</staticText>			<staticText>				<reportElement width="100" y="0" x="0" height="30"></reportElement>				<text>![CDATA[zbid]]</text>			</staticText>			<staticText>				<reportElement width="100" y="0" x="0" height="30"></reportElement>				<text>![CDATA[bemerkung]]</text>			</staticText>			<staticText>				<reportElement width="100" y="0" x="0" height="30"></reportElement>				<text>![CDATA[ausgewaehlt]]</text>			</staticText>			<staticText>				<reportElement width="100" y="0" x="0" height="30"></reportElement>				<text>![CDATA[bezahlt]]</text>			</staticText>			<staticText>				<reportElement width="100" y="0" x="0" height="30"></reportElement>				<text>![CDATA[oztyp]]</text>			</staticText>			<staticText>				<reportElement width="100" y="0" x="0" height="30"></reportElement>				<text>![CDATA[status]]</text>			</staticText>		</band>	</pageHeader>	<detail>		<band height="30">			<textField>				<reportElement width="100" y="0" x="0" height="20"></reportElement>				<textFieldExpression>					<![CDATA[$F{belegid}]]>				</textFieldExpression>			</textField>			<textField>				<reportElement width="100" y="0" x="0" height="20"></reportElement>				<textFieldExpression>					<![CDATA[$F{adressid}]]>				</textFieldExpression>			</textField>			<textField>				<reportElement width="100" y="0" x="0" height="20"></reportElement>				<textFieldExpression>					<![CDATA[$F{datum}]]>				</textFieldExpression>			</textField>			<textField>				<reportElement width="100" y="0" x="0" height="20"></reportElement>				<textFieldExpression>					<![CDATA[$F{netto}]]>				</textFieldExpression>			</textField>			<textField>				<reportElement width="100" y="0" x="0" height="20"></reportElement>				<textFieldExpression>					<![CDATA[$F{mwst}]]>				</textFieldExpression>			</textField>			<textField>				<reportElement width="100" y="0" x="0" height="20"></reportElement>				<textFieldExpression>					<![CDATA[$F{rabatt}]]>				</textFieldExpression>			</textField>			<textField>				<reportElement width="100" y="0" x="0" height="20"></reportElement>				<textFieldExpression>					<![CDATA[$F{zbid}]]>				</textFieldExpression>			</textField>			<textField>				<reportElement width="100" y="0" x="0" height="20"></reportElement>				<textFieldExpression>					<![CDATA[$F{bemerkung}]]>				</textFieldExpression>			</textField>			<textField>				<reportElement width="100" y="0" x="0" height="20"></reportElement>				<textFieldExpression>					<![CDATA[$F{ausgewaehlt}]]>				</textFieldExpression>			</textField>			<textField>				<reportElement width="100" y="0" x="0" height="20"></reportElement>				<textFieldExpression>					<![CDATA[$F{bezahlt}]]>				</textFieldExpression>			</textField>			<textField>				<reportElement width="100" y="0" x="0" height="20"></reportElement>				<textFieldExpression>					<![CDATA[$F{oztyp}]]>				</textFieldExpression>			</textField>		</band>	</detail></jasperReport>
Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

 Hi Patrick, when you define a textfield, its textFieldExpression should have the type (class attribute) of the data it holds, by default the type is java.lang.String. In your code, the "datum" field has a java.util.Date type, then in the textFieldExpression tis can´t be cast to a java.lang.String (is not possible to cas a Date to a String in java).

...<field name="datum" class="java.util.Date" />...

<textFieldExpression> //String is the default type

<![CDATA[$F{datum}]]> //datum is a Date!

</textFieldExpression>

[/code]

 

If you want to show the date as a String the you can use the toString method:

<textFieldExpression> //String is teh default type

<![CDATA[$F{datum}.toString()]]>

</textFieldExpression>

[/code]

 

If you want to hold the date as a java.util.Date then you must add the class attribute to the testFieldExpression 

<textFieldExpression class="java.util.Date">

<![CDATA[$F{datum}]]>

</textFieldExpression>

[/code]

Regards.

Alvaro

Link to comment
Share on other sites

  • 8 years later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...