奇怪的Integer.parseInt异常(Strange Integer.parseInt exception)

编程入门 行业动态 更新时间:2024-10-20 16:36:18
奇怪的Integer.parseInt异常(Strange Integer.parseInt exception)

线程“Thread-2”中的异常java.lang.NumberFormatException:对于输入字符串:“3”

int test = Integer.parseInt(result[0]);

当我尝试将“3”转换为整数时,这是我不断得到的错误。 好吧,我通过RS-232端口收到这个“3”,所以也许这就是造成错误的原因。

如果有人知道可能导致这种情况的原因,我们将不胜感激。

Exception in thread "Thread-2" java.lang.NumberFormatException: For input string: "3"

int test = Integer.parseInt(result[0]);

This is the error I keep getting when I'm trying to convert "3" to an integer. Well I'm receiving this "3" through a RS-232 port, so maybe this is what is causing the error.

If anybody has any idea what could be causing this it would be appreciated.

最满意答案

结果[0]的数据类型是什么? 如果它是一个字符串,你确定它周围没有空格或新行吗?

试试result[0].trim()

What is the data type of result[0]? If it's a string, are you sure there are no spaces or new lines around it?

Try result[0].trim()

更多推荐

本文发布于:2023-08-07 02:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1458515.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:异常   奇怪   Integer   parseInt   Strange

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!