Join the Stack Overflow Community
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

the eclipse tells that lang and i cant find a solution

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);

I read from file in this format name-adres,phone and ad in arraylist put for phone i have problem

share|improve this question

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.

use long instead

long phone = Long.parseLong(s2[1].trim() )
share|improve this answer

The real problem is that a phone number is not an integer. It is a String. You should not store it as a number, for reasons similar to the problem you are encountering now. The same applies for ZIP codes, sports team's jersey numbers, and a host of other "fake" numbers.

share|improve this answer
    
+1 to Tom G, using Long or other numeric type can cause issues in future. – Alex Stybaev Dec 18 '12 at 14:38
1  
This is the correct response. What if the phone number is 000-0001. Do you really want to store it as 1? What would you show the user? – jsn Dec 18 '12 at 14:43
    
+1 tom, agreed ... way better to make it an string than long .. sad i dint get that tought while answering :P, – PermGenError Dec 18 '12 at 14:48
    
I tern the int varible to String ? – Βίκτορας ανδρεάδης Dec 18 '12 at 15:09

A Signed 32 Bit Integer can only read upto 2^31. You have to use a bigger datatype. long will get you up to 2^63.

share|improve this answer

The basic thing is that, we don't need a phone number to be part of a arithmetic calculation like addition, subtraction etc. Hence we can take it as a String safely.

share|improve this answer
2463025552 

is a out of range for int data type, try giving lesser number. Also check if it is in correct number format (like no spaces etc)

share|improve this answer
    
It is a given phone number, we can't really change it so it fits into an int. – Paŭlo Ebermann Jul 5 '13 at 8:55

Change your data type to long or bigint. Your string is too long then int thats why it have exception..

share|improve this answer

Integer.parseInt( s2[1].trim() ); here is your problem. So, change your parsing Integer to Long

share|improve this answer
    
I change from Integer to long and works perfect.. A lot of thanks for help. – Βίκτορας ανδρεάδης Dec 19 '12 at 9:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.