joannem Posted March 11, 2008 Share Posted March 11, 2008 Hello, I am using an xml file as my datasource. One of my fields is a comma delimited list which I split and put into an array.... I have a variable assigned for each array element... so, $V{hr1} = $V{vends}[0]... $V{hr2} = $V{vends}[1].... I want to take some of my variables and add them together. $V{hr1} + $V{hr2} + $V{hr3} My array is defined as a string. I've tried a couple of different options of defining my variables hr1, hr2, hr3.... as integers..... as well as I've tried them as string but nothing works to be able to add them together. I can get it to concatenate the values of hr1, hr2 and hr3 but I cannot get them to add. I have a variable $V(hr_int4) where the expression is Integer.valueOf($V{hr1} + $V{hr2} + $V{hr3}) when I view this I see the concatenated values of the fields as if they were strings. I've tried Integer.parseInt($V[hr1} + $V{hr2} + $V{hr3}) it didn't work..... I get an error "Incompatible conditional types int + Integer". I've also gotten the error "The operator + is undefined for the argument type(s) java.lang.Integer, java.lang.Integer. If anyone can tell me what I am missing doing, it would be greatly appreciated. Thanks you in advance. Link to comment Share on other sites More sharing options...
svenn Posted March 11, 2008 Share Posted March 11, 2008 "+" is use to concatenate string values together so you cannot do Integer.parseInt($V[hr1} + $V{hr2} + $V{hr3}) Parse each value independently then add them up Integer.parseInt($V[hr1}) + Integer.parseInt($V{hr2}) + Integer.parseInt($V{hr3})) 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