1

我收到一个奇怪的数字格式异常。我知道,如果在我尝试创建一个新的 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]
4

1 回答 1

3

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

于 2013-09-26T05:42:39.140 回答