Search code examples
androidkotlinnumberformatter

"java.lang.NoSuchMethodError: No static method" error when using Android NumberFormatter


According to the documentation this line should produce an output of "// 1,234 in en-US":

println(NumberFormatter.withLocale(ULocale.ENGLISH).format(123).toString())

Instead it's throwing this error:

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)

Solution

  • Added in API level 30

    It works on android 11+. What's your version?