java - 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);
解决方案
推测:有前导或尾随空格。最简单的解决方案(我看到的),使用正则表达式从输入中去除非数字。喜欢,
String claimStr = getText(MyClaimsObject.estClaimAmount).replaceAll("\\D+", "");
int claimAmount = Integer.parseInt(claimStr);
推荐阅读
- python - 我的 pygame 屏幕没有使用 pygame.display.update 更新事件
- python - AttributeError:“应用程序”对象没有属性“rp_toggle_button”
- c# - 出口后浮动上升较慢
- python - Python 和 Selenium 访问保存的网页
- android-studio - 如何在片段中的 recyclerView 上打开不同的活动?
- php - EasyAdmin 3:OneToMany 字段名称未显示在主页上
- flutter - 我如何制作一个带有监听器颤动的动态控制器
- javascript - 内部服务器错误(我遵循了这封信的教程,但我仍然收到 2 个错误)
- nsis - 如何在 NSIS 中以管理员权限在 CMD 中运行命令?
- elasticsearch - 当我在我的 kafka 源连接器配置中使用“output.json.formatter”时,Mongo Elasticsearch Sink 连接器不起作用