简体   繁体   English

java.lang.NumberFormatException:对于输入字符串:“”

[英]java.lang.NumberFormatException: For input string: “ ”

So the issue I am getting seems to be a kind of common, however the missing points in each of the issues I checked online was different from the one I experiencing. 因此,我遇到的问题似乎是一种常见问题,但是我在线检查的每个问题中的缺失点与我遇到的问题有所不同。

So what I am trying to do is converting a string back to long. 所以我想做的就是将字符串转换回long。 The string was read from a file as following 从文件中读取字符串如下

484625517161611266 string 454511457536

I read the line into an array and I printed the array which shows the writing went fine. 我将行读入数组中,并打印了该数组,这表明编写效果很好。 Then I tried convert to long as below 然后我尝试转换为long如下

long id = Long.parseLong(splitted[0],10);

However I got this issue 但是我遇到了这个问题

java.lang.NumberFormatException: For input string: "484625517161611266"

Normally the common issues with this type of exception would be trying to convert letter or trying to convert numbers that contains spaces. 通常,此类异常的常见问题是尝试转换字母或尝试转换包含空格的数字。 Another issue might be a certain mistake while reading the file. 另一个问题可能是读取文件时的某个错误。

However I check all of those possibilities and still I am getting this exception 但是,我检查了所有这些可能性,但仍然出现此异常

Any Suggestions ? 有什么建议么 ? Thanks in advance 提前致谢

java.lang.NumberFormatException: For input string: "484625517161611266" java.lang.NumberFormatException:对于输入字符串:“ 484625517161611266”

There is a \ (ZERO WIDTH NO-BREAK SPACE) character in your input 您的输入中有一个\ (零宽度无\空格)字符

Try copying it and pasting it in plain text editor, remove this junk character 尝试将其复制并粘贴到纯文本编辑器中,删除该垃圾字符

to remove this character you can use 要删除此字符,您可以使用

inputNumberString.replaceAll("\uFEFF", "").trim()

note: trim() just to remove any other whitespace if present 注意: trim()仅删除存在的其他空白

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM