报错信息:Json返回字段为null,而用的地方需要数字转换
报错日志
E/CrashReport: java.lang.NumberFormatException: Bad offset/length: offset=0 len=0 in.length=0
具体报错代码
DecimalFormat("###.##").format(BigDecimal(item.priceOfficial?:"0"))
解决方案:
val priceOfficial = item.priceOfficial?.trim()?.replace("null", "")
DecimalFormat("###.##").format(BigDecimal(if (priceOfficial.isNullOrEmpty()) "0" else priceOfficial))
紧急解决方案:(定位兼容性问题)
后台做数据判Null处理。线上发版


本文探讨了如何处理Json返回的null值导致的NumberFormatException,并提供了两种解决方案,包括后台数据校验和紧急版本发布。重点在于确保数据转换的兼容性和有效性。
1068

被折叠的 条评论
为什么被折叠?



