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 ?
6 Answers:
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
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
Because it is the value of the object you are using in the variable. that means, if you use a string, you'd have to put it like this:
String.valueOf("mystring")
and if your variable is of type integer:
Integer.valueOf(23)
Alex
All good things come to those who wait
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
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
I had the same problem. Its a bug.
See: http://jasperforge.org/projects/ireport/tracker/view.php?id=4640