makroll10 Posted February 29, 2016 Share Posted February 29, 2016 Hello,in iReport i want to read with the "substring" function a part from a text field like: $F{Textfeld}.substring(5, 9)For example of"10000 015" the part "015""20000 023" the part "023""30000 057" the part "057"After that I want to create a variable $V{Sum} (typ = java.lang.Integer, calculation = sum), to convert the results in a number and create a sum. In the example it is 95.Unfortunately, it has been abort with "java.lang.String cannot be cast to java.lang.Number". But what is wrong with it? Markus Link to comment Share on other sites More sharing options...
Solution hozawa Posted February 29, 2016 Solution Share Posted February 29, 2016 Should go to StackOverflow and ask there how to convert String to Integer in Java.http://stackoverflow.com/ Link to comment Share on other sites More sharing options...
makroll10 Posted February 29, 2016 Author Share Posted February 29, 2016 Hello,a reference to another board is/ was not the solution to the problem.I Think the problem lies in the conversion of the string through by the substring commandand the subsequent conversion into the variable...Markus Link to comment Share on other sites More sharing options...
lucianc Posted March 1, 2016 Share Posted March 1, 2016 You need to manually convert the String into an integer by doing Integer.valueOf($F{Textfeld}.substring(5, 9)) or INTEGER_VALUE($F{Textfeld}.substring(5, 9))(INTEGER_VALUE is a builtin function available in recent versions, it might not work in iReport.)Regards,Lucian Link to comment Share on other sites More sharing options...
kavyatg1990 Posted April 9, 2018 Share Posted April 9, 2018 Hi Parsing Methods in Java Convert String to IntIn Java there are two methods to convert String to Int, they are.Integer.parseInt()Integer.valueOf()1. Convert String to Int using Integer.parseInt()The Integer.parseInt() is a static method of Integer class used in java to converts string to primitive integer.ExampleString ‘100’ to primitive integer 100Note:Parsing is a process of converting one data type to another. For example String to integer is a best way to convert string to int i hope this may be use full. 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