<small id='R7WiZ'></small><noframes id='R7WiZ'>

      <bdo id='R7WiZ'></bdo><ul id='R7WiZ'></ul>

    <i id='R7WiZ'><tr id='R7WiZ'><dt id='R7WiZ'><q id='R7WiZ'><span id='R7WiZ'><b id='R7WiZ'><form id='R7WiZ'><ins id='R7WiZ'></ins><ul id='R7WiZ'></ul><sub id='R7WiZ'></sub></form><legend id='R7WiZ'></legend><bdo id='R7WiZ'><pre id='R7WiZ'><center id='R7WiZ'></center></pre></bdo></b><th id='R7WiZ'></th></span></q></dt></tr></i><div id='R7WiZ'><tfoot id='R7WiZ'></tfoot><dl id='R7WiZ'><fieldset id='R7WiZ'></fieldset></dl></div>
    <legend id='R7WiZ'><style id='R7WiZ'><dir id='R7WiZ'><q id='R7WiZ'></q></dir></style></legend><tfoot id='R7WiZ'></tfoot>

        Integer.parseInt(String str) java.lang.NumberFormatException

        Integer.parseInt(String str) java.lang.NumberFormatException: Errors(Integer.parseInt(String str) java.lang.NumberFormatException: 错误)

        <tfoot id='zJYy7'></tfoot>
          <tbody id='zJYy7'></tbody>
            • <bdo id='zJYy7'></bdo><ul id='zJYy7'></ul>

              <small id='zJYy7'></small><noframes id='zJYy7'>

              <legend id='zJYy7'><style id='zJYy7'><dir id='zJYy7'><q id='zJYy7'></q></dir></style></legend>
                <i id='zJYy7'><tr id='zJYy7'><dt id='zJYy7'><q id='zJYy7'><span id='zJYy7'><b id='zJYy7'><form id='zJYy7'><ins id='zJYy7'></ins><ul id='zJYy7'></ul><sub id='zJYy7'></sub></form><legend id='zJYy7'></legend><bdo id='zJYy7'><pre id='zJYy7'><center id='zJYy7'></center></pre></bdo></b><th id='zJYy7'></th></span></q></dt></tr></i><div id='zJYy7'><tfoot id='zJYy7'></tfoot><dl id='zJYy7'><fieldset id='zJYy7'></fieldset></dl></div>

                  本文介绍了Integer.parseInt(String str) java.lang.NumberFormatException: 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I keep getting number format expectations, even though I'm trimming the strings and they don't contain non numerical characters bizarrely it works for some numbers and not others. Below is an example of a string I get number format exception for. Also, any string starting with 0 e.g "0208405223", is returned 208405223, there's no zero anymore is that supposed to happen?

                  String n="3020857508";
                  Integer a = Integer.parseInt(n.trim());
                  System.out.println(a);
                  

                  This is the exception:

                  Exception in thread "main" java.lang.NumberFormatException: For input string: "3020857508"
                      at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
                      at java.lang.Integer.parseInt(Integer.java:583)
                      at java.lang.Integer.parseInt(Integer.java:615)
                      at JavaBeans.Main.main(Main.java:15)
                  

                  解决方案

                  It's because 3020857508 exceeds Integer.MAX_VALUE. You should use long to convert the string to number.

                  java> String n="3020857508";
                  //=> java.lang.String n = "3020857508"
                  java> Integer a = Integer.parseInt(n.trim());
                  //=> java.lang.NumberFormatException: For input string: "3020857508"
                  java> Integer.MAX_VALUE
                  //=> java.lang.Integer res2 = 2147483647
                  java> Long a = Long.parseLong(n.trim());
                  //=>java.lang.Long a = 3020857508
                  

                  The above is javarepl output.

                  If you are using JDK9 or above, you can see the same result in jshell.

                  jshell> String n="3020857508"
                  n ==> "3020857508"
                  
                  jshell> Integer a = Integer.parseInt(n.trim())
                  |  Exception java.lang.NumberFormatException: For input string: "3020857508"
                  |        at NumberFormatException.forInputString (NumberFormatException.java:65)
                  |        at Integer.parseInt (Integer.java:652)
                  |        at Integer.parseInt (Integer.java:770)
                  |        at (#2:1)
                  
                  jshell> Integer.MAX_VALUE
                  $3 ==> 2147483647
                  
                  jshell> Long a = Long.parseLong(n.trim());
                  a ==> 3020857508
                  

                  这篇关于Integer.parseInt(String str) java.lang.NumberFormatException: 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                    <bdo id='4FfSo'></bdo><ul id='4FfSo'></ul>

                      <tbody id='4FfSo'></tbody>
                    <tfoot id='4FfSo'></tfoot>

                    <small id='4FfSo'></small><noframes id='4FfSo'>

                          • <i id='4FfSo'><tr id='4FfSo'><dt id='4FfSo'><q id='4FfSo'><span id='4FfSo'><b id='4FfSo'><form id='4FfSo'><ins id='4FfSo'></ins><ul id='4FfSo'></ul><sub id='4FfSo'></sub></form><legend id='4FfSo'></legend><bdo id='4FfSo'><pre id='4FfSo'><center id='4FfSo'></center></pre></bdo></b><th id='4FfSo'></th></span></q></dt></tr></i><div id='4FfSo'><tfoot id='4FfSo'></tfoot><dl id='4FfSo'><fieldset id='4FfSo'></fieldset></dl></div>

                            <legend id='4FfSo'><style id='4FfSo'><dir id='4FfSo'><q id='4FfSo'></q></dir></style></legend>