Note that there are some explanatory texts on larger screens.

plurals
  1. POCompatibility for Java library methods that require Android API level 9?
    primarykey
    data
    text
    <p>Some Java library methods like <code>DecimalFormat.setRoundingMode</code> have a <code>@since 1.6</code> entry in their documentation.</p> <pre><code>/** ... * @since 1.6 */ public void setRoundingMode(RoundingMode roundingMode) { ... } </code></pre> <p>When I tried to use this method compiled under Android 4.2.2 and JDK 1.6 with my <code>android:minSdkVersion</code> set to 7 as shown,</p> <pre><code>myNumberFormat.setRoundingMode(RoundingMode.DOWN); </code></pre> <p>Android Lint underlined <code>setRoundingMode</code> in red for me and told me that</p> <pre><code>Call requires API level 9 (current min is 7): java.text.NumberFormat#setRoundingMode </code></pre> <p>How and <em>why</em> can the Android API restrict which Java library methods I can and cannot use? I cleaned my project and the Lint error disappeared. My project compiled with no errors and ran on a device running Android 2.2.3 (API 8).<br> My program crashed with:</p> <pre><code>05-09 11:32:38.436: E/AndroidRuntime(2074): Caused by: java.lang.NoSuchMethodError: java.text.NumberFormat.setRoundingMode </code></pre> <p>The Android documentation confirms that <a href="http://developer.android.com/reference/java/text/NumberFormat.html#setRoundingMode(java.math.RoundingMode)" rel="nofollow noreferrer">setRoundingMode</a>, <a href="http://developer.android.com/reference/java/lang/Math.html#copySign(double,%20double)" rel="nofollow noreferrer">copySign</a>, and others were added in API level 9. <strong>Does that mean that devices running Android OS level 8 and below are specifically compiled/built with JDK 1.5?</strong> </p> <p>And I can understand that. <strong>But is it impossible for the Android Support Library (or anything else) to allow us to use these methods?</strong> </p> <p>Related to <a href="https://stackoverflow.com/questions/4072313/rounding-half-up-with-decimal-format-in-android">Rounding Half Up with Decimal Format in Android</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload