首页 > 解决方案 > java.lang.NumberFormatException:

问题描述

Integer value = Rs 5000

读取该整数值并将其按空格分割,以便我只能获得整数值。但是当我执行脚本时它显示“5000”。为什么会这样。

日志错误:

java.lang.NumberFormatException:对于输入字符串:“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);

标签: javaseleniumappium

解决方案


推测:有前导或尾随空格。最简单的解决方案(我看到的),使用正则表达式从输入中去除非数字。喜欢,

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

推荐阅读