开发者

Strange Integer.parseInt exception

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

 int test = Integer.parseInt(result开发者_Python百科[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.


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()


Take a look at the char values of result[0] when this occurs. It might be possible that this "3" is in fact not the ASCII character '3' but some strange Unicode character that just looks like a 3.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜