Hi,
I want to count the number of row where a fields is equals ="hello". I did a new variabile (type counter) and put in a variable expression something like this:
$F(nameField).equals("hello")
but it doesn't work: CannotÂcastÂfromÂbooleanÂtoÂObject
What's the problem??
I want to count the number of row where a fields is equals ="hello". I did a new variabile (type counter) and put in a variable expression something like this:
$F(nameField).equals("hello")
but it doesn't work: CannotÂcastÂfromÂbooleanÂtoÂObject
What's the problem??
2 Answers:
Posted on January 17, 2007 at 10:58am
There was an excellent post on this just a couple of days ago, but I can't find it.
The crux of the problem is that your comparison results in a primitive boolean result but your variable is defined as an Integer object.
What you need to put in your variable's expression is something like this:
$F{ProtocolName}.compareTo("hello")==0 ? new java.lang.Integer(1) : null
If you wanted to use a Sum variable instead of a counter then your variable's expression would be
$F{ProtocolName}.compareTo("hello")==0 ? new java.lang.Integer(1) : new java.lang.Integer(0)
The crux of the problem is that your comparison results in a primitive boolean result but your variable is defined as an Integer object.
What you need to put in your variable's expression is something like this:
$F{ProtocolName}.compareTo("hello")==0 ? new java.lang.Integer(1) : null
If you wanted to use a Sum variable instead of a counter then your variable's expression would be
$F{ProtocolName}.compareTo("hello")==0 ? new java.lang.Integer(1) : new java.lang.Integer(0)
Posted on January 17, 2007 at 1:33pm
You should buy the documentation, it's worth it - saved me a lot of trouble.
Some more info on count: Count will incriment when it reaches any non-null data, therefore you have to use a single line expression to say that if it's NOT equal to your comparison, consider it null.
I like using methods that return a boolean, but depending on what JRE you're using, you'll have to choose your own method. If you're returning a boolean on count simply say:
$F{ProtocolName}.equals("hello") ? "count me" : null
where count me could be literally anything.
On the contrary, if you want to count everything that DOES NOT meet that criteria, simply change it to:
$F{ProtocolName}.equals("hello") ? null : "count me"
Some more info on count: Count will incriment when it reaches any non-null data, therefore you have to use a single line expression to say that if it's NOT equal to your comparison, consider it null.
I like using methods that return a boolean, but depending on what JRE you're using, you'll have to choose your own method. If you're returning a boolean on count simply say:
$F{ProtocolName}.equals("hello") ? "count me" : null
where count me could be literally anything.
On the contrary, if you want to count everything that DOES NOT meet that criteria, simply change it to:
$F{ProtocolName}.equals("hello") ? null : "count me"