gpt4 book ai didi

java - Android 中奇怪的 NumberFormatException

转载 作者:行者123 更新时间:2023-12-01 18:16:40 25 4
gpt4 key购买 nike

它看起来像整数,但它不能用 Integer.parse() 解析,我该如何修复它?

 int a= Integer.parseInt(lhs.getViewCount());

 Caused by: java.lang.NumberFormatException: Invalid int: "6125635424"
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parse(Integer.java:378)
at java.lang.Integer.parseInt(Integer.java:366)
at java.lang.Integer.parseInt(Integer.java:332)
at com.youtubetracker.adapters.MyChannelListAdapter$1.compare(MyChannelListAdapter.java:46)
at com.youtubetracker.adapters.MyChannelListAdapter$1.compare(MyChannelListAdapter.java:37)

最佳答案

始终使用BigInteger过长并漂浮。

BigInteger value= new BigInteger(lhs.getViewCount());

您可以将该值转换为 intlongfloat

表单 Java 文档 intValue()

Converts this BigInteger to an int. This conversion is analogous to a narrowing primitive conversion from long to int as defined in section 5.1.3 of The Java™ Language Specification: if this BigInteger is too big to fit in an int, only the low-order 32 bits are returned. Note that this conversion can lose information about the overall magnitude of the BigInteger value as well as return a result with the opposite sign.

关于java - Android 中奇怪的 NumberFormatException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29114723/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com