【发布时间】:2011-03-31 20:50:06
【问题描述】:
我写了一个将字符串转换为整数的函数
if ( data != null )
{
int theValue = Integer.parseInt( data.trim(), 16 );
return theValue;
}
else
return null;
我有一个字符串 6042076399,它给了我错误:
Exception in thread "main" java.lang.NumberFormatException: For input string: "6042076399"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:461)
这不是将字符串转换为整数的正确方法吗?
【问题讨论】:
-
请注意,通过将 16 指定为
parseInt的第二个参数,您将字符串解析为十六进制数。
标签: java numberformatexception