问题描述
根据 documentation,此行应产生“// 1,234 in en-US”的输出:
println(NumberFormatter.withLocale(ULocale.ENGLISH).format(123).toString())
相反,它抛出了这个错误:
java.lang.NoSuchMethodError: No static method withLocale(Landroid/icu/util/ULocale;)Landroid/icu/number/LocalizednumberFormatter; in class Landroid/icu/number/NumberFormatter; or its super classes (declaration of 'android.icu.number.NumberFormatter' appears in /apex/com.android.runtime/javalib/core-libart.jar)
解决方法
Added in API level 30
它适用于 android 11+。你的版本是什么?