【问题标题】:Stramge Error on Numerical Strings: NumberFormatException数字字符串上的奇怪错误:NumberFormatException
【发布时间】:2013-09-26 05:39:45
【问题描述】:

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

【问题讨论】:

    标签: java string numberformatexception


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-07
      • 2021-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多