我是靠谱客的博主 老实自行车,最近开发中收集的这篇文章主要介绍java invalid integer,Java异常无效INT长整型,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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长整型所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(33)

评论列表共有 0 条评论

立即
投稿
返回
顶部