Please do not scold strongly, it did not work with XML, only I study. So far I go from a simple XmlPullParser to understand the principle of operation. Actually the question itself: I parse the document from the site, from it you need to pull out several fields and add a request to the key. If the file is located locally in the project, there are no questions, I figured it out. But here I am trying to pull the same thing out of the network and it does not work. + Not quite until the end I understand how to properly attach the heder. (I do it through the browser, I see the answer) Actually the code itself
listView = findViewById(R.id.listView1); new GetWeatherDataTask(this, URL_CONNECT).execute(); and the background is:
public class GetWeatherDataTask extends AsyncTask<String[], Void, List<Employee>> { private MainActivity activity; private ProgressDialog pDialog; public GetWeatherDataTask(MainActivity activity, String url) { this.activity = activity; } @Override protected void onPreExecute() { super.onPreExecute(); pDialog = new ProgressDialog(activity); pDialog.setTitle("Get Weather Information from XML"); pDialog.setMessage("Loading..."); pDialog.show(); } @Override protected List<Employee> doInBackground(String[]... params) { try { URL url=new URL("https://rasp.rw.by/api/ru/index/route/?from=Иваново&to=Москва"); HttpURLConnection connection=(HttpURLConnection)url.openConnection(); connection.setDoInput(true); connection.setRequestProperty("X-AppId", "97377f7b702d7198e47a2bf12eec744d5"); connection.connect(); InputStream is = connection.getInputStream(); XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); XmlPullParser parser = factory.newPullParser(); parser.setInput(is, "UTF-8"); parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); int eventType = parser.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { String tagname = parser.getName(); //index рабочий тег if (eventType == XmlPullParser.START_TAG) { if (tagname.equalsIgnoreCase("index")) { //на теге индекс начинаем выдергивать employee = new Employee(); employees.add(employee); } }else if (eventType == XmlPullParser.TEXT) { text = parser.getText(); }else if (eventType == XmlPullParser.END_TAG) { if (tagname.equalsIgnoreCase(TITLE)) { employee.setId(text); } else if (tagname.equalsIgnoreCase(TRAIN_NUMBER)) { employee.setTrain_number(text); } else if (tagname.equalsIgnoreCase(TRAIN_DAYS)) { employee.setTrain_days(text); } else if (tagname.equalsIgnoreCase(MIN_PRICE)) { employee.setMin_price(text); } else if (tagname.equalsIgnoreCase(FROM_TIME)) { employee.setFrom_time_formatted(text); } else if (tagname.equalsIgnoreCase(TO_TIME)) { employee.setTo_time_formatted(text); } else if (tagname.equalsIgnoreCase(TRAIN_STOPS)) { employee.setName(text); } else if (tagname.equalsIgnoreCase(DURATION)) { employee.setSalary(text); } } eventType = parser.next(); } } catch (XmlPullParserException | IOException e) {e.printStackTrace(); Log.e("AsyncTask", "GOOD"); Log.e("AsyncTask", String.valueOf(employees)); } catch (Exception e) { e.printStackTrace(); Log.e("AsyncTask", "exception"); return null; } return employees; } @Override protected void onPostExecute(List<Employee> result) { pDialog.dismiss(); ArrayAdapter<Employee> adapter =new ArrayAdapter<Employee> (getApplicationContext(),android.R.layout.simple_list_item_1, employees); listView.setAdapter(adapter); } } Log.e("AsyncTask", "GOOD"); и [] is Log.e("AsyncTask", "GOOD"); и [] displayed in the logs Log.e("AsyncTask", "GOOD"); и [] Log.e("AsyncTask", "GOOD"); и []
[_body: protected] =>
[_directory:protected] => Api 05-10 16: 04: 01.711 24921-25023 / com.roman.xml E / AsyncTask: [_controller: protected] => Index 05-10 16: 04: 01.711 24921-25023 / com.roman.xml E / AsyncTask: [_action: protected] => route 05-10 16: 04: 01.711 24921-25023 / com.roman.xml E / AsyncTask: [_uri: protected] => api / ru / index / route 05-10 16:04: 01.711 24921-25023 / com.roman.xml E / AsyncTask: [_external: protected] => 05-10 16: 04: 01.711 24921-25023 / com.roman.xml E / AsyncTask: [_params: protected] => Array
( 05-10 16: 04: 01.711 24921-25023 / com.roman.xml E / AsyncTask: [lang] => en 05-10 16: 04: 01.711 24921-25023 / com.roman.xml E / AsyncTask: [lang_sensitive ] => 1 05-10 16: 04: 01.711 24921-25023 / com.roman.xml E / AsyncTask: [domain] => api 05-10 16: 04: 01.711 24921-25023 / com.roman.xml E / AsyncTask: [debug] => 05-10 16: 04: 01.711 24921-25023 / com.roman.xml E / AsyncTask:) [10] => Array 05-10 16: 04: 01.720 24921-25023 / com.roman .xml E / AsyncTask: (05-10 16: 04: 01.721 24921-25023 / com.roman.xml E / AsyncTask: [file] => /home/rasprwby/rasp.rw.by/www/index.php 05 -10 16: 04: 01.721 24921-25023 / com.roman.xml E / AsyncTask: [line] => 118 05-10 16: 04: 01.721 24921-25023 / com.roman.xml E / AsyncTask: [function] => execute 05-10 16: 04: 01.721 24921-25023 / com.roman.xml E / AsyncTask: [class] => Kohana_Request 05-10 16: 04: 01.721 24921-25023 / com.roman.xml E / AsyncTask : [type] => -> 05-10 16: 04: 01.721 24921-25023 / com.roman.xml E / AsyncTask: [args] => Array

"GOOD"that the red font is written in the logs? In general, you have a glass error . - woesssBufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8")); String line; while ((line = br.readLine()) != null) { System.out.println(line); }BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8")); String line; while ((line = br.readLine()) != null) { System.out.println(line); }BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8")); String line; while ((line = br.readLine()) != null) { System.out.println(line); }, I hope you figure it out. - woesssconnection.getResponseCode()to the log before parsing - if not 200, then sort out the server API to make sure the request is woesss