此问题已经在这里有了答案:
我有一个简单的程序,该程序将使用parseInt
将字符串转换为int,但是无法转换为获取NumberFormatException
的方法
public static void main(String[] args) { String invoiceNo = "3466002000"; System.out.println(Integer.parseInt(invoiceNo)); }
异常跟踪:
Exception in thread "main" java.lang.NumberFormatException: For input string: "3466002000"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at com.utils.ExcelFileUtil.main(ExcelFileUtil.java:159)
我有一个简单的程序,它将使用parseInt将字符串转换为int,但是无法转换为获取NumberFormatException public static void main(String [] args){
3466002000
的值太大,无法将其解析为int
。使用long
代替:public static void main(String[] args) {
String invoiceNo = "3466002000";
System.out.println(Long.parseLong(invoiceNo));
}