java.lang.NumberFormatException:用于输入字符串 [英] java.lang.NumberFormatException: For input string
问题描述
eclipse告诉lang我无法找到解决方案
the eclipse tells that lang and i cant find a solution
线程main中的异常java.lang.NumberFormatException:用于输入字符串:2463025552
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(未知来源)Main.main的
(Main.java:31)
Exception in thread "main" java.lang.NumberFormatException: For input string: "2463025552" at java.lang.NumberFormatException.forInputString(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at Main.main(Main.java:31)
String s2[]=s.split("\\,");
Records rec=new Records();
rec.setName(s1[0]);
rec.setAddres(s2[0]);
phone = Integer.parseInt( s2[1].trim() );
System.out.println(phone);
我从这个格式的文件中读取名称-adres,手机和广告在arraylist put for phone我有问题
I read from file in this format name-adres,phone and ad in arraylist put for phone i have problem
推荐答案
如果传递的字符串不是整数的有效表示,Integer.parseInt会抛出NumberFormatException。在这里你试图传递 2463025552 ,这是超出整数范围。
Integer.parseInt throws a NumberFormatException if the passed string is not a valid representation of an integer. here you are trying to pass 2463025552 which is out of integer range.
使用long而不是
long phone = Long.parseLong(s2[1].trim() )
这篇关于java.lang.NumberFormatException:用于输入字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!