Some Java library methods, such as DecimalFormat.setRoundingMode , have an @since 1.6 entry in their documentation.
public void setRoundingMode(RoundingMode roundingMode) { ... }
When I tried to use this method compiled under Android 4.2.2 and JDK 1.6, and my android:minSdkVersion set to 7, as shown,
myNumberFormat.setRoundingMode(RoundingMode.DOWN);
Android Lint highlighted setRoundingMode red for me and told me that
Call requires API level 9 (current min is 7): java.text.NumberFormat
How and why can the Android API limit which Java library methods I can and cannot use? I cleaned up my project and the Lint bug disappeared. My project was compiled without errors and launched on a device running Android 2.2.3 (API 8).
My program crashed:
05-09 11:32:38.436: E/AndroidRuntime(2074): Caused by: java.lang.NoSuchMethodError: java.text.NumberFormat.setRoundingMode
Android documentation confirms that setRoundingMode , copySign, and others have been added to API level 9. Does this mean that devices running Android 8 and below are specially compiled / created using JDK 1.5?
And I can understand that. But doesn't the Android support library (or something else) allow us to use these methods?
Associated with Rounding twice with decimal in Android
source share