在Java中转换整数字符串时出现NumberFormatException [英] NumberFormatException when converting Integer String in Java
本文介绍了在Java中转换整数字符串时出现NumberFormatException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我声明此变量:
private String numCarteBancaireValide=String.valueOf(((Integer.parseInt(Config.NUM_CARTE_BANCAIRE_VALIDE) ) + (Integer.parseInt("0000000000000001"))));
Config.NUM_CARTE_BANCAIRE_VALIDE is a string.
执行后,我收到此错误消息:
After Execution, I receive this error message :
java.lang.NumberFormatException: For input string: "4111111111111111"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:583)
at java.lang.Integer.parseInt(Integer.java:615)
请,您能提出建议吗?
推荐答案
使用 Long.parseLong()
,因为您的参数对于 Integer
而言太大.(一个整数的最大值为 2147483647
)
Use Long.parseLong()
, as your parameter is too large for an Integer
. (Maximum for an integer is 2147483647
)
PS:使用 Integer.parseInt("0000000000000001")
也没有多大意义,您可以将其替换为 1
.
PS: using Integer.parseInt("0000000000000001")
doesn't make much sense either, you could replace this with 1
.
这篇关于在Java中转换整数字符串时出现NumberFormatException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文