1
以下方法接受XML文件和Xpath表達式,並將結果作爲字符串數組返回。它意味着使用API級別4(Android 1.6)在Android設備上運行。問題是我在模擬器上運行時總是收到java.lang.VerifyError。Document.selecNodes(String e)在Android 1.6上返回java.lang.VerifyError
任何想法可能是錯的?
@SuppressWarnings("unchecked")
private String[] evaluate(File file, String exp) {
String[] values = null;
try{
SAXReader reader = new SAXReader();
//new line added because xpath not supported on oppaz android 1.6
org.dom4j.Document doc = reader.read(file);
java.util.List<Node> nl = null;
try{
//An error is always generated here java.lang.VerifyError
nl = doc.selectNodes(exp);
}
catch(java.lang.VerifyError e){
System.out.println("The following error occurred Mayne");
e.printStackTrace();
}
Object[] obj = nl.toArray();
int j = obj.length;
//Find out how many nodes were returned
values =new String[j];
for(int i=0;i<j;i++){
Element element = (Element) nl.get(i);
NodeList nl2 = element.getChildNodes();
String value = ((Node) nl2.item(0)).getNodeValue();
values[i] = value;
}
}
catch(Exception e){
e.printStackTrace();
}
return values;
}