概述
I'm currently developing a math application that makes long computations. I'm getting java.lang.NumberFormatException: Invalid int: "..." error (where the ... is replaced by a very long number) whenever I type an integer that contains more than 9 digits. When I type in an integer that is less than or equal to 9 digits, the application runs fine. I need the output to be an int (i.e. no decimal places). Not quite sure why the error's occurring.
The bit of code that's causing the problem is:
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.NUMBER);
int inp = Integer.parseInt(message);
解决方案
The maximum value for an int is 231-1, i.e. 2,147,483,647. If you try to parse a larger number than that, the exception will be thrown.
If you need to handle larger numbers, either use long for a generally larger range (up to 263-1) or BigInteger for an arbitrary size.
最后
以上就是老实自行车为你收集整理的java invalid integer,Java异常无效INT长整型的全部内容,希望文章能够帮你解决java invalid integer,Java异常无效INT长整型所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复