daniele Posted January 17, 2007 Share Posted January 17, 2007 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?? Link to comment Share on other sites More sharing options...
jmurray Posted January 17, 2007 Share Posted January 17, 2007 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) Link to comment Share on other sites More sharing options...
schaibaa Posted January 17, 2007 Share Posted January 17, 2007 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" Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now