本文介绍了为什么StrinUtils阿帕奇类没有在Android的认可?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么导入org.apache.commons.lang.StringUtils 不能在Android的默认进口的。
我一定要包括外部库?然后,我在哪里可以在网上找到该库?
包com.myapps.urlencoding;
进口android.app.Activity;
进口org.apache.commons.lang.StringUtils;
公共类恩codeIdUtil延伸活动{
/ **第一次创建活动时调用。 * /
私有静态长乘数=的Long.parseLong(1zzzz,36);
/ **
*恩codeS的ID。
*参数ID标识为en code
* @返回EN codeD字符串
* /
公共静态字符串连接code(长ID){
返回StringUtils.reverse(Long.toString((ID *乘数),35));
}
/ **
*德codeS的EN $ C $光盘ID。
* @参数EN codeDID的EN codeDID脱code
* @返回的Id
* @throws IllegalArgumentException - 如果连接codeDID是不是一个有效的连接$ C $光盘ID。
* /
公共静态龙德code(字符串连接codeDID)
抛出:IllegalArgumentException - {
很长的产品;
尝试 {
产品=的Long.parseLong(StringUtils.reverse(EN codeDID),35);
}赶上(例外五){
抛出新抛出:IllegalArgumentException();
}
如果(0 =产品%乘数||产品<!0){
抛出新抛出:IllegalArgumentException();
}
回到产品/乘法器;
}
}
解决方案
的Apache Commons Lang中是一个单独的库。你可以找到它这里。
Why import org.apache.commons.lang.StringUtils cannot be imported in android by default.
Do i have to include an external library? Then where can i find that library on the web?
package com.myapps.urlencoding;
import android.app.Activity;
import org.apache.commons.lang.StringUtils;
public class EncodeIdUtil extends Activity {
/** Called when the activity is first created. */
private static Long multiplier=Long.parseLong("1zzzz",36);
/**
* Encodes the id.
* @param id the id to encode
* @return encoded string
*/
public static String encode(Long id) {
return StringUtils.reverse(Long.toString((id*multiplier), 35));
}
/**
* Decodes the encoded id.
* @param encodedId the encodedId to decode
* @return the Id
* @throws IllegalArgumentException if encodedId is not a validly encoded id.
*/
public static Long decode(String encodedId)
throws IllegalArgumentException {
long product;
try {
product = Long.parseLong(StringUtils.reverse(encodedId), 35);
} catch (Exception e) {
throw new IllegalArgumentException();
}
if ( 0 != product % multiplier || product < 0) {
throw new IllegalArgumentException();
}
return product/multiplier;
}
}
解决方案
Apache Commons lang is a separate library. You can find it here.
这篇关于为什么StrinUtils阿帕奇类没有在Android的认可?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!