我有一个应用程序,我需要解析一个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!!!
}
什么是你的错误?清单上的权限允许互联网?以及您作为手机,模拟器或真正的手机使用了什么? – JPM