java.lang.NumberFormatException: For input string

前端 未结 7 578
栀梦
栀梦 2020-11-28 16:15

the eclipse tells that lang and i cant find a solution

Exception in thread \"main\" java.lang.NumberFormatException: For input string: \"2463025552\"

相关标签:
7条回答
  • 2020-11-28 16:23

    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() )
    
    0 讨论(0)
  • 2020-11-28 16:23

    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.

    0 讨论(0)
  • 2020-11-28 16:30
    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)

    0 讨论(0)
  • 2020-11-28 16:33

    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.

    0 讨论(0)
  • 2020-11-28 16:34

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

    0 讨论(0)
  • 2020-11-28 16:37

    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.

    0 讨论(0)
提交回复
热议问题