【问题标题】:Exception in thread "main" java.lang.NumberFormatException: For input string: "8/3/2012"线程“main”java.lang.NumberFormatException 中的异常:对于输入字符串:“8/3/2012”
【发布时间】:2014-06-07 02:57:27
【问题描述】:

为什么我会收到这些错误消息。

Exception in thread "main" java.lang.NumberFormatException: For input string: "8/3/2012"
    at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1222)
    at java.lang.Double.parseDouble(Double.java:510)
    at com.exel.raf.seeit.ExecuteImport.excelDtToString(ExecuteImport.java:713)
    at com.exel.raf.seeit.ExecuteImport.generateItemHistorySql(ExecuteImport.java:649)
    at com.exel.raf.seeit.ExecuteImport.execute(ExecuteImport.java:56)
    at com.exel.raf.seeit.ExecuteImport.main(ExecuteImport.java:38)
    Process exited with exit code 1.

【问题讨论】:

  • 发布导致它的代码。
  • 8/3/2012 是字符串值,您将其解析为 number , Double.parseDouble 请参阅代码的 510 行
  • 是什么让您认为“2012 年 8 月 3 日”是一个有效数字。你的代码有问题。请分享导致此错误的代码片段。

标签: java numberformatexception


【解决方案1】:

如果您尝试将字符串转换为数字。在上述情况下,我认为您的字符串是“8/3/2012”。要转换为任何数字,除了数字之外,您不能有任何字符,如果需要小数,则可以使用 double。

这看起来像一个日期,请探索 Date 类,看看如何将它转换为日期。

【讨论】:

    【解决方案2】:

    日期 8/3/2012 不是正确的数字类型。检查您将其解析为 Double 的代码行。

    来自 java 文档,

    抛出表明应用程序已尝试将字符串转换为其中一种数字类型,但该字符串没有适当的格式。

    refer here

    【讨论】:

      猜你喜欢
      • 2014-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多