java - 数字字符串上的奇怪错误 : NumberFormatException

标签 java string numberformatexception

我收到一个奇怪的数字格式异常。我知道如果在我尝试创建一个新的 Integer 包装器对象时出现奇怪的字符,它将无法工作,但我的输入字符串似乎是普通的数字字符串。是否有其他原因导致我出现此错误?

systemtest:
    [junit] Running simpledb.systemtest.ScanTest
    [junit] Testsuite: simpledb.systemtest.ScanTest
    [junit] Tests run: 3, Failures: 0, Errors: 3, Time elapsed: 0.097 sec
    [junit] Tests run: 3, Failures: 0, Errors: 3, Time elapsed: 0.097 sec
    [junit] 
    [junit] Testcase: testSmall took 0.025 sec
    [junit]     Caused an ERROR
    [junit] For input string: "4386131530"
    [junit] java.lang.NumberFormatException: For input string: "4386131530"
    [junit]     at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    [junit]     at java.lang.Integer.parseInt(Integer.java:484)
    [junit]     at java.lang.Integer.parseInt(Integer.java:514)
    [junit]     at simpledb.HeapPageId.hashCode(HeapPageId.java:44)

...

[junit] Testcase: testCache took 0.029 sec
    [junit]     Caused an ERROR
    [junit] For input string: "8140111260"
    [junit] java.lang.NumberFormatException: For input string: "8140111260"
    [junit]     at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    [junit]     at java.lang.Integer.parseInt(Integer.java:484)
    [junit]     at java.lang.Integer.parseInt(Integer.java:514)
    [junit]     at simpledb.HeapPageId.hashCode(HeapPageId.java:44)
    [junit]     at simpledb.BufferPool.getPage(BufferPool.java:70)
    [junit]     at simpledb.HeapFile$HFTupleIterator.retrieveTuples(HeapFile.java:200)
    [junit]     at simpledb.HeapFile$HFTupleIterator.open(HeapFile.java:141)
    [junit]     at simpledb.SeqScan.open(SeqScan.java:92)
    [junit]     at simpledb.systemtest.SystemTestUtil.matchTuples(SystemTestUtil.java:121)
    [junit]     at simpledb.systemtest.SystemTestUtil.matchTuples(SystemTestUtil.java:107)
    [junit]     at simpledb.systemtest.SystemTestUtil.matchTuples(SystemTestUtil.java:100)
    [junit]     at simpledb.systemtest.ScanTest.testCache(ScanTest.java:99)
    [junit]

最佳答案

您的数字太大,无法放入整型变量中。但是,这种大小的整数适合 long。将声明更改为 long(或者可能是 BigDecimal),或者使用更小的数字 <= Integer.MAX_VALUE;

关于java - 数字字符串上的奇怪错误 : NumberFormatException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19020181/

相关文章:

java - Cassandra 控制台日志消息

java - 找到从左上角到右下角的所有路径问题。以数组为参数的递归解法输出说明

java - 我如何使用trim()方法来完成这项工作?我需要读取txt文件,同时忽略空白行和以 "//"开头的行

php - 检查字符串名称中的点

java - NumberFormatException:无限或 NaN

java - 输入字符串 : "15,7" 的 NumberFormatException

java - Android 页面在图片下载过程中崩溃

android - String[] 数组无法正常工作

java - 多行 Java 字符串的任何 future 计划

java - 验证字符串是否为整数 (numberFormatException)