简体   繁体   中英

java.lang.NumberFormatException:

Integer value = Rs 5000

reading that integer value and split it by space so that I can get only the integer value. But when i am executing the script it shows " 5000".Why is it so.

Log error:

java.lang.NumberFormatException: For input string: "5000 at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:580)

int claimAmount= Integer.parseInt(getText(MyClaimsObject.estClaimAmount).split( " ")[1]);
System.out.println(claimAmount);

Speculation: there is leading or trailing white space. Easiest solution (that I see), use a regular expression to strip non-digits from your input. Like,

String claimStr = getText(MyClaimsObject.estClaimAmount).replaceAll("\\D+", "");
int claimAmount = Integer.parseInt(claimStr);

Potentially you have something trailing the 5000 value eg unprintable UTF characters. The exception text should be For input string: "5000" , you are missing the closing " character.

Ensure that you are cleaning up the user input eg by disallowing non-numeric characters in the input.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM