package edu.spring.data;import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;import org.w3c.dom.*;
public class DataHelp {
public static File xmlFile = null;
public static Document doc;
public static Document getDocument()throws Exception
{
xmlFile = new File("datasource/contact.xml");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(xmlFile);
return doc;
}
public static ArrayList GetInfo() throws Exception
{
ArrayList list=new ArrayList();
doc=getDocument();
Element root=doc.getDocumentElement();
NodeList names=root.getElementsByTagName("name");
NodeList mobilePhones=root.getElementsByTagName("mobilePhone");
NodeList imageIds=root.getElementsByTagName("imageId");
for(int i=0; i<names.getLength(); i++)
{//加入hashmap
HashMap map=new HashMap();
map.put("name", names.item(i).getTextContent());//java程序中可以,在android中这一句就
                                                                       //报错:没有为类型 Node 定义方法                                                                      //getTextContent()让我情何以堪
//System.out.println(names.item(i).getTextContent());
map.put("mobilePhone", mobilePhones.item(i).getTextContent());
//System.out.println(mobilePhones.item(i).getTextContent());
map.put("imageId",imageIds.item(i).getTextContent());
//System.out.println(imageIds.item(i).getTextContent());
list.add(map);
}
return list;
}}

解决方案 »

  1.   

    楼主最好把XML的内容也贴出来
      

  2.   

    初步判断可能是因为android里面的包有问题 就是说
    java中的 Node类 和你android中的Node 并不是同一个包里面的 
    可能是android自动引入包时出了问题;
    Node这个类在android 不止一个存在
      

  3.   


    <?xml version="1.0" encoding="utf-8"?>
    <adressbook>
    <people name="张三" 
        mobilePhone="188" 
        otherContact="1121" 
        officePhone="0004500" 
        familyPhone="5444544" 
        email="09251" 
        position="学生" 
        company="xx" 
        adress="厦门xx" 
        zipCode="计算机学院" 
        imageId="2130837517"/>
    </adressbook>
      

  4.   

    换个高点的android版本2.3测试过没问题!