我正在尝试在Android中使用org.apache.commons.collections.CollectionUtils。样本低于
import java.util.ArrayList;
import org.apache.commons.collections.CollectionUtils;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class CheckCommonsActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String email1 = "xyz@gmail.com";
String email2 = "abc@gmail.com";
String email3 = "mnp@gmail.com";
String email4 = null;
ArrayList<String> emailList1 = new ArrayList<String>();
emailList1.add(email4);
emailList1.add(email1);
emailList1.add(email2);
emailList1.add(email3);
ArrayList<String> emailList2 = new ArrayList<String>();
emailList2.add(email3);
emailList2.add(email2);
emailList2.add(email1);
boolean isEqual = CollectionUtils.isEqualCollection(emailList1,
emailList2);
TextView text = (TextView) findViewById(R.id.text);
text.setText(String.valueOf(isEqual));
}
}
我已将commons-collections-3.2.1.jar导入Android项目的Build Path,但我在运行时收到错误java.lang.NoClassDefFoundError: org.apache.commons.collections.CollectionUtils
。
EDIT1
由于
答案 0 :(得分:6)
您必须将库放在Android项目的/ libs(非/ lib)文件夹中
编辑:我假设你把它放在/ lib文件夹中,因为这是一个常见的失败。在您添加的屏幕截图中可以看到您将lib作为外部jar包含在内。无论如何..无论你把它放在/ lib还是作为外部jar,解决方案都是一样的:create / libs文件夹并将lib放在那里