Jump to content
We've recently updated our Privacy Statement, available here ×

Problem with variables - initial value expression


gobenn71

Recommended Posts

Hi all,

 

although i'm not new to JasperReports and iReport, i still don't understand the concept of the initial variable expression !

Can someone explain to me, why i always get an error like 'the inital value calss is not compatible with the variable's class', when i put the variable expression into the initial value expression ? my variable expression is generating a string and the  variable has the type string.

 

I simply don't get what the concept behind the initial value expression is, can someone explain it to me ?

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Just remember that IReport considers the values you put as objects, and not as primitives. That is why you would have to put your String value into quotes like this:

"mystring"

and when using an integer, you would have to define the value as java expects it:

new Integer(24)

and when using an array list :

new ArrayList(Arrays.asList(new Long[] {new Long(22), new Long(33)}));

 

and so on

Think that everything inside IReport is java. Objects, methods etc.

 

Hope this helps

Alexandru Ersenie

All good things come to those who wait

qants.wordpress.com

Link to comment
Share on other sites

 
 
But why does iReport then say 'the inital value class is not compatible with the variable's class', when i put "" or new String("") into the initial value expression of a variable which creates a String ? Is this possibly a bug in iReport 3.5.3 ?

 

Post Edited by gobenn71 at 11/09/2009 12:28

Link to comment
Share on other sites

I have still the same problem. I still  don't get it. Is this a bug within iReport 3.5.3 ?

I have a variable which should count the occurences of a group. The definition is as follows :

variable class : java.lang.Integer

calculation : count

Reset type : report

 

variable expression : ($V{IndexCommodity_COUNT} != null  && $V{IndexCommodity_COUNT}.intValue()==1) ? "" : null

(this trick to count the occurences of a group was published in one of the iReport guide books...)

 

initial value expression  Integer.valueOf(1)

 

I get the following error : The initial value class is not compatible with the variable's class

 

WHY ?



Post Edited by gobenn71 at 11/10/2009 07:46
Link to comment
Share on other sites

  • 2 months later...

Here since your variable type is Integer you  cannot return string value.

*****variable expression : ($V{IndexCommodity_COUNT} != null  && $V{IndexCommodity_COUNT}.intValue()==1) ? "" : null)

just ignore the initial value expression. Leave it blank and run the report. If you still want the initial value of the variable as 1, Just set the variable expression as follows.

variable expression : ($V{IndexCommodity_COUNT} != null  && $V{IndexCommodity_COUNT}.intValue()==1) ? 0 : 1)

Hope this helps

Buddhi

Link to comment
Share on other sites

  • 3 months 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...