开发者社区> 问答> 正文

遇到 NumberFormatException 怎么解决?java报错

遇到 NumberFormatException 怎么解决?java报错

在编写java的样例代码时出现这种问题。这种情况应该如何解决和避免那?

错误信息:

public class Test {
    public static void main(String[] args){
        int num = Integer.parseInt(".10");
    }
}

Exception in thread "main" java.lang.NumberFormatException: For input string: ".10"

原因是什么,为什么会发生异常,以及下面到底发生了什么。如果有人能帮忙?提前谢谢

展开
收起
爱吃鱼的程序员 2020-05-26 14:10:19 1417 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    楼主。看了你的错误信息,很明显根据提示可以知道,错误是因为java.lang.NumberFormatException 字符串转换为数字异常,在使用时要确保转换的字符串格式符合转换后的数据类型。

    2020-05-26 15:09:53
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载