Note that there are some explanatory texts on larger screens.

plurals
  1. POBizarre behaviour when using Apache Commons lib in Android
    primarykey
    data
    text
    <p>I'm using commons-lang3-3.0.1.jar, in order to utilise the <code>StrSubstitutor</code> class. Check this out...</p> <p>The following code is called in from my SyncAdapter, it crashes constructing the StrSubstitutor:</p> <pre><code>public static String makeGetPlansQueryString(Bundle params) { Map&lt;String, String&gt; valuesMap = new HashMap&lt;String, String&gt;(); valuesMap.put(REQUEST_PARAM_APIUSERNAME, API_USERNAME); valuesMap.put(REQUEST_PARAM_APIPASSWORD, API_PASSWORD); //... etc. etc. String xmlTemplate = VendApplication.getContext().getString(R.string.XMLREQUEST_GET_PLANS); StrSubstitutor subst = new StrSubstitutor(valuesMap); // &lt;-- Crashes in here. return subst.replace(xmlTemplate); } </code></pre> <p>Error output:</p> <pre><code> 11-02 14:36:08.439: ERROR/AndroidRuntime(9244): FATAL EXCEPTION: SyncAdapterThread-1 11-02 14:36:08.439: ERROR/AndroidRuntime(9244): java.lang.ExceptionInInitializerError 11-02 14:36:08.439: ERROR/AndroidRuntime(9244): at com.conducthq.android.vend.webapi.WebAPIRequestHelper.makeGetPlansQueryString(WebAPIRequestHelper.java:68) 11-02 14:36:08.439: ERROR/AndroidRuntime(9244): at com.conducthq.android.vend.webapi.WebAPIClient.createHTTPRequest(WebAPIClient.java:121) 11-02 14:36:08.439: ERROR/AndroidRuntime(9244): at com.conducthq.android.vend.webapi.WebAPIClient.processRequest(WebAPIClient.java:55) 11-02 14:36:08.439: ERROR/AndroidRuntime(9244): at com.conducthq.android.vend.webapi.SyncAdapter.onPerformSync(SyncAdapter.java:39) 11-02 14:36:08.439: ERROR/AndroidRuntime(9244): at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:163) 11-02 14:36:08.439: ERROR/AndroidRuntime(9244): Caused by: java.lang.ExceptionInInitializerError 11-02 14:36:08.439: ERROR/AndroidRuntime(9244): at org.apache.commons.lang3.text.StrMatcher.stringMatcher(StrMatcher.java:206) 11-02 14:36:08.439: ERROR/AndroidRuntime(9244): at org.apache.commons.lang3.text.StrSubstitutor.&lt;clinit&gt;(StrSubstitutor.java:112) 11-02 14:36:08.439: ERROR/AndroidRuntime(9244): ... 5 more 11-02 14:36:08.439: ERROR/AndroidRuntime(9244): Caused by: java.lang.NullPointerException 11-02 14:36:08.439: ERROR/AndroidRuntime(9244): at org.apache.commons.lang3.StringUtils.&lt;clinit&gt;(StringUtils.java:717) 11-02 14:36:08.439: ERROR/AndroidRuntime(9244): ... 7 more </code></pre> <p>If I add this <strong>one line</strong> to my HomeActivity (launched on app start), the above code works perfectly:</p> <pre><code>StrSubstitutor sub = new StrSubstitutor(new HashMap&lt;String, String&gt;()); </code></pre> <p>Weird right? How does this line affect different code running on a different thread at a different point in time? Any Android gurus out there that can shed some light on this? Is there some weird Android JAR loading bug I don't know about? @_@</p> <p>I'm using Android 2.1 SDK on a LG-P350. I've reproduced this behaviour with the super simple example code from the Apache Commons API doc on StrSubstitutor: <a href="http://commons.apache.org/lang/api-3.0.1/org/apache/commons/lang3/text/StrSubstitutor.html" rel="nofollow">http://commons.apache.org/lang/api-3.0.1/org/apache/commons/lang3/text/StrSubstitutor.html</a></p>
    singulars
    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