奇怪的Integer.parseInt异常(Strange Integer.parseInt exception)
int test = Integer.parseInt(result[0]);线程“Thread-2”中的异常java.lang.NumberFormatException:对于输入字符串:“3”
当我尝试将“3”转换为整数时,这是我不断得到的错误。 好吧,我通过RS-232端口收到这个“3”,所以也许这就是造成错误的原因。
如果有人知道可能导致这种情况的原因,我们将不胜感激。
int test = Integer.parseInt(result[0]);Exception in thread "Thread-2" java.lang.NumberFormatException: For input string: "3"
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()
更多推荐
发布评论