输入字符串999999999的NumberFormatException [英] NumberFormatexception for input string 999999999

查看:187
本文介绍了输入字符串999999999的NumberFormatException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的html代码

<div class="form-group col-md-6">
    <input type="text" class="form-control" name="phonenumber" placeholder="Enter Phone Number">
</div>

这是我的controller

int phonenumber=Integer.parseInt(request.getParameter("phonenumber").trim());

我得到NumberFormatException for input string '9999999999'

解决方法.

即使是一个数字,我为什么也不能解析它?

Even though it is a number why cannot I parse it?

推荐答案

9999999999不在int数据类型(-2 31 到2 Integer.MIN_VALUE Integer.MAX_VALUE 常量.

9999999999 is outside the valid range of values for the int data type (-231 to 231-1, inclusive), as specified by the Integer.MIN_VALUE and Integer.MAX_VALUE constants.

您不能在int中表示完整的电话号码,因此您必须省略前缀和区号(0000000-9999999).否则,请改用long(-2 63 到2 63 -1(含)),Long.parseLong()将很乐意处理9999999999.

You cannot represent a full phone number in an int, you would have to omit the prefix and area code (0000000 - 9999999). Otherwise, use a long instead (-263 to 263-1, inclusive), Long.parseLong() will happily handle 9999999999.

这篇关于输入字符串999999999的NumberFormatException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆