Jump to content
Changes to the Jaspersoft community edition download ×

Report working with iReport but JR throw an error


bob007

Recommended Posts

Hi,

 

I make my reports programmatically and I got this exception on compilation with JasperReports  BUT when I export my report in .jrxml to try it with IReports its working (with a queryString).

The error seem to occur because the compiler try to cast my report variable ($V{totalPriorite}) from Integer to String.

 

What can cause this error ?

 

I join the output .jrxml.

 

Thank you,

Philippe

 

 

MY ERROR:

_________________________________________________________________

 

net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:

1. Cannot cast from Integer to String

                value = (java.lang.String)(((java.lang.Integer)variable_totalPriorite.getValue())); //$JR_EXPR_ID=18$

                        <------------------------------------------------------------------------>

2. Cannot cast from Integer to String

                value = (java.lang.String)(((java.lang.Integer)variable_totalPriorite.getOldValue())); //$JR_EXPR_ID=18$

                        <--------------------------------------------------------------------------->

3. Cannot cast from Integer to String

                value = (java.lang.String)(((java.lang.Integer)variable_totalPriorite.getEstimatedValue())); //$JR_EXPR_ID=18$

                        <--------------------------------------------------------------------------------->

3 errors

 

            at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:195)

            at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:219)

            at JasperReportChartConstructor.compileReport(JasperReportChartConstructor.java:319)

            ...

 

 

JAVA: ADDING THE VARIABLE

_______________________________________________

 

       JRDesignVariable variable = new JRDesignVariable();

      variable.setName("totalPriorite");

      variable.setResetType(JRDesignVariable.RESET_TYPE_GROUP);

      variable.setResetGroup(group);

      variable.setValueClass(java.lang.Integer.class);

      variable.setCalculation(JRDesignVariable.CALCULATION_COUNT);

      JRDesignExpression variableExpression = new JRDesignExpression();

      variableExpression.setValueClass(java.lang.String.class);

      variableExpression.setText("$F{priorite}");

      JRDesignExpression initialValueExpression = new JRDesignExpression();

      initialValueExpression.setValueClass(java.lang.Integer.class);

      initialValueExpression.setText("new java.lang.Integer(0)");

      variable.setExpression(variableExpression);

      variable.setInitialValueExpression(initialValueExpression);

     

         try {

         jasperDesign.addVariable(variable);

      } catch (JRException e) {

         // TODO Auto-generated catch block

         e.printStackTrace();

      }

 



Post Edited by bob007 at 04/22/2009 20:58
Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

 

Ok its solved,

 

It was a stupid error.

I declared the wrong class for the using of the variable then the compiler was trying to cast Integer to Sring.

 

its working now

 

Regards,

Philippe



Post Edited by bob007 at 04/23/2009 18:26
Link to comment
Share on other sites

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...