在Android中使用Apache Commons库时的奇怪行为
我正在使用commons-lang3-3.0.1.jar,以便使用在Android中使用Apache Commons库时的奇怪行为,android,apache-commons,Android,Apache Commons,我正在使用commons-lang3-3.0.1.jar,以便使用StrSubstitutor类。看看这个 以下代码是从我的SyncAdapter中调用的,它在构造StrSubstitutor时崩溃: public static String makeGetPlansQueryString(Bundle params) { Map<String, String> valuesMap = new HashMap<String, String>(); val
StrSubstitutor
类。看看这个
以下代码是从我的SyncAdapter中调用的,它在构造StrSubstitutor时崩溃:
public static String makeGetPlansQueryString(Bundle params)
{
Map<String, String> valuesMap = new HashMap<String, String>();
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); // <-- Crashes in here.
return subst.replace(xmlTemplate);
}
public静态字符串makeGetPlansQueryString(Bundle参数)
{
映射值Map=newhashmap();
valuesMap.put(请求参数APIUSERNAME、API用户名);
valuesMap.put(请求参数APIPASSWORD、API密码);
//等等等等等等。
String xmlTemplate=VendApplication.getContext().getString(R.String.XMLREQUEST\u GET\u PLANS);
StrSubstitutor subst=new StrSubstitutor(valuesMap);//您的崩溃发生在StringUtils的静态初始值设定项中,它试图从当前线程获取上下文类加载器-显然是试图获取java.text.Normalizer$Form类。因此,是的,getContextClassLoader()存在一些奇怪的问题返回null
更新
这个错误显然在中提到过,所以我想您可以强制设置上下文类加载器,这样就可以了
Thread.currentThread().setContextClassLoader(this.getClassLoader());
StrSubstitutor sub = new StrSubstitutor(new HashMap<String, String>());
Thread.currentThread().setContextClassLoader(this.getClassLoader());