2011-10-14 55 views
1

我有一个应用程序,我需要解析一个XML。 当我在Java Project上这样做时,可以工作。但是,当我尝试在Android项目上执行此操作时,URL无法连接,我正在使用XPath。 代码:Android - 使用XPath访问WebService

private static final String STRING_XML =“http:// localhost:50645/WebServiceClientes.asmx/ListaReservas”;

....

// prepare a URL to the geocoder 
URL url = new URL(STRING_XML); 

// prepare an HTTP connection to the geocoder 
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 

Document geocoderResultDocument = null; 
try { 
    // open the connection and get results as InputSource. 
    conn.connect(); 
    InputSource geocoderResultInputSource = new InputSource(conn.getInputStream()); 

    // read result and parse into XML Document 
    geocoderResultDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(geocoderResultInputSource); 
} finally { 
    conn.disconnect(); //The debug stops here, so, Disconnect!!! 
} 
+0

什么是你的错误?清单上的权限允许互联网?以及您作为手机,模拟器或真正的手机使用了什么? – JPM

回答

0

AndroidManifest.xml添加更多uses-permissionINTERNET

此外,finally肯定是所谓的每一次。

0

我正在使用本地主机Web服务,并访问它,需要使用端口8080.