以前,我使用assets文件夹中的XML文件。该应用可以很好地阅读。下一步我想把这个XML放在Web服务器上。但在这个阶段,应用程序无法识别任何数据。它让我困惑了几天。尝试从URL获取XML
AssetManager asset = getAssets();
InputStream input = asset.open("student.xml");
List<Student> list = ParserByPULL.getStudents(input);
一切工作正常,如果资产文件夹中的文件。 然后我试图从URL中获取它。
String path = "http://fthgyj.tup632.cnaaa11.com/student.xml";
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5000);
conn.setRequestMethod("GET");
InputStream input = url.openConnection().getInputStream();
List<Student> list = ParserByPULL.getStudents(input);
我已经添加了在清单文件中连接INTERNET的权限。 有没有人有这个想法?
那又怎么了?你得到异常或什么,只是空的回应? – vilpe89
NetworkOnMainThreadException也许? – laalto
告诉我们您问题的确切症状。让我们猜测是不好的,除此之外,你不会得到你的答案 – kiruwka