NumberFormatException when trying to parse Strings from .getText();

夙愿已清 提交于 2019-12-02 09:17:06

I assume it's because of parsing an empty string,

No it is because the String it is attempting to parse is Total: 8.78

quick way to remove that label is (assumming you have control over the label

substring("Total:".length()).trim();

From the exception it is showing you are trying to parse string: "Total: 8.78" to integer. Try to remove Total: String then parse the same.

Do it like:

String input = totalLbl.getText();
input = input.replace("Total:","").trim();
Double d = Double.parseDouble(input) * 0.20;

Please try this and let me know if you need further help.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!