数字字符串的奇怪错误:NumberFormatException

时间:2013-09-26 05:39:45

标签: java string numberformatexception

我收到一个奇怪的数字格式异常。我明白,如果我尝试创建一个新的整数包装器对象时有奇怪的字符,它将无法工作,但似乎我的输入字符串是正常的数字字符串。还有其他原因我可能会收到此错误吗?

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]

1 个答案:

答案 0 :(得分:3)

您的数字太大,无法容纳整数变量。但是,此大小的整数适合long。将声明更改为long(或可能BigDecimal),或使用较小的数字< = Integer.MAX_VALUE;