Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 正在尝试从URL获取XML_Android_Xml_Url_Xmlpullparser - Fatal编程技术网

Android 正在尝试从URL获取XML

Android 正在尝试从URL获取XML,android,xml,url,xmlpullparser,Android,Xml,Url,Xmlpullparser,之前,我使用了assets文件夹中的XML文件。应用程序可以很好地阅读它。下一步我想把这个XML放到web服务器上。但在这个阶段,应用程序无法识别任何数据。这几天让我很困惑 AssetManager asset = getAssets(); InputStream input = asset.open("student.xml"); List<Student> list = ParserByPULL.getStudents(input); AssetManager资产=getAs

之前,我使用了assets文件夹中的XML文件。应用程序可以很好地阅读它。下一步我想把这个XML放到web服务器上。但在这个阶段,应用程序无法识别任何数据。这几天让我很困惑

AssetManager asset = getAssets();
InputStream input = asset.open("student.xml");
List<Student> list = ParserByPULL.getStudents(input); 
AssetManager资产=getAssets();
InputStream输入=asset.open(“student.xml”);
List List=ParserByPULL.getStudents(输入);
如果文件位于assets文件夹中,则一切正常。 然后我试着从一个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);
字符串路径=”http://fthgyj.tup632.cnaaa11.com/student.xml";
URL=新URL(路径);
HttpURLConnection conn=(HttpURLConnection)url.openConnection();
连接设置连接超时(5000);
conn.setRequestMethod(“GET”);
InputStream输入=url.openConnection().getInputStream();
List List=ParserByPULL.getStudents(输入);
我已在清单文件中添加了连接INTERNET的权限。
有人知道这件事吗?

我想你需要打电话

conn.connect();
InputStream input = conn.getInputStream();
然后检查是否已获取xml:

BufferedReader reader = new BufferedReader(new InputStreamReader(input));
StringBuilder builder = new StringBuilder();
String line;

while ((line = reader.readLine()) != null) {
    builder.append(line);
}
reader.close();
Log.d("tag", "output: " + builder.toString());

尝试从URL中提取并解析XML文件


那么出了什么问题?您是否得到异常或什么,只是空响应?可能是NetworkOnMainThreadException?请告诉我们您的问题的确切症状。让我们猜是不好的,而且你不会得到你的答案,我很抱歉。屏幕上没有显示任何内容。但该应用程序可以正常运行(logcat上没有错误)。我尝试过,但仍然无法运行。无论如何,非常感谢。你确定你没有从输入流中得到任何东西吗?检查我的最新答案谢谢,我会逐行阅读。你觉得这个有用吗?