【发布时间】:2011-10-14 14:29:15
【问题描述】:
我有一个应用程序,我需要解析一个 XML。 当我在 Java 项目上这样做时,工作正常。但是,当我尝试在 Android 项目上执行此操作时,URL 无法连接,我使用的是 XPath。 代码:
私有静态最终字符串 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!!!
}
【问题讨论】:
-
你的错误是什么?清单上的权限允许互联网吗?你用的是什么手机、模拟器还是真手机?