简体   繁体   English

无法将String解析为long

[英]Cannot parse String to long

I am trying to convert a String of digits to a long using Long.parseLong(s) , but I get a NumberFormatException . 我正在尝试使用Long.parseLong(s)将数字String转换为long ,但是我得到了NumberFormatException The string contains just digits. 该字符串仅包含数字。 Long.decode(s) doesn't work either. Long.decode(s)也不起作用。 Does anyone know how to resolve this problem? 有谁知道如何解决这个问题?

With other strings, this class works without a problem. 与其他字符串一起使用时,此类不会出现问题。

One reason might be leading or trailing whitespace characters, which can be removed using trim(). 原因之一可能是空格字符的前导或尾随,可以使用trim()将其删除。 The other reason might be that the number is out of range of long ( which is a rare case actually, but you might check that as well). 另一个原因可能是该数字超出了long的范围(实际上这是一种罕见的情况,但您也可以进行检查)。 Can you provide a sample string ? 您可以提供示例字符串吗?

Have answer! 有答案! this string was nulled in current thread before calling next thread, where long value must use. 在调用必须使用long值的下一个线程之前,此字符串在当前线程中为空。 ParseLong could not keep finish parsing :) ParseLong无法完成解析:)

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

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