本文介绍了电话号码上有ParseInt NumberFormatException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试解析电话号码时出现以下错误,5554567899

I'm getting the following error when trying to parse the phone number, "5554567899"

java.lang.NumberFormatException: For input string: "5554567899"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:495)
at java.lang.Integer.parseInt(Integer.java:527)
...

显然,电话号码可以解析。我甚至引用了,字节码结果是

Obviously, the phone number is able to be parsed. I even referenced this question, and the byte code result was

53,53,53,52,53,54,55,56,57,57,

因此字符串中没有不可见的字符。我很难过,有人可以帮忙吗?

So there's no invisible characters in the string. I'm stumped, can anyone help?

以下是引发错误的代码部分,供参考:

Here's the section of the code that's throwing the error, for reference:

String fullNumber = null;
        for(Phone phone : party.getPhones()) {
            if(phone != null && !phone.getDialNumber().isEmpty()) {
                if(!phone.getAreaCode().isEmpty()) {
                    fullNumber = phone.getAreaCode();
                }
                fullNumber += phone.getDialNumber();
                if(phone1 == null || phone1.equals(0)) {
                    LOGGER.debug(displayCharValues(fullNumber));
                    phone1 = Integer.parseInt(fullNumber);
                }
         }

phone1 Java.lang.Integer 类型。

推荐答案

该值超出int范围。将其解析为长变量。

The value exceeds the int range. Parse it into a long variable.

简单测试:

int i = 5554567899;

是编译时错误:int类型的文字5554567899超出范围

is a compile time error: "The literal 5554567899 of type int is out of range"

这篇关于电话号码上有ParseInt NumberFormatException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 04:02