Immediately vyrozhu thanks for the previous answer. When parsing, the data is displayed as needed. But when you click on the link, it displays an error, tried to attach the domain name http://ktits.ru to the link header, then it displays just an empty window. I also tried to display log.i, I didn't get any results. The stream for working with jsoup left in the main activity, did not take out in a separate Java class. The data from the site is placed in an array through map.put. Here is the code of all activity: Logs: logs HTML code of the site: HTML

 public class MainActivity extends Activity { private TextView textView; private ListView listView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView=(ListView)findViewById(R.id.listView1); textView=(TextView)findViewById(R.id.textView); ParseTitle parseTitle = new ParseTitle(); parseTitle.execute(); try { final HashMap<String,String> hashMap = parseTitle.get(); final ArrayList<String> arrayList = new ArrayList<>(); for(Map.Entry entry : hashMap.entrySet()){ arrayList.add(entry.getKey().toString()); } ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, arrayList); listView.setAdapter(arrayAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ParseText parseText = new ParseText(); parseText.execute(hashMap.get(arrayList.get(position))); try { listView.setVisibility(View.GONE); textView.setText(parseText.get()); } catch (ExecutionException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } }); } catch (ExecutionException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } @Override public void onBackPressed(){ listView.setVisibility(View.VISIBLE); textView.setVisibility(View.GONE); } class ParseText extends AsyncTask<String,Void,String>{ @Override protected String doInBackground(String... strings) { String str = ""; try { Document document = Jsoup.connect(strings[0]).get(); Elements elements = document.select("div[class=text]").get(0).getElementsByTag("p"); // Log.i(str,"fgds"); }catch (IOException e){ e.printStackTrace(); } return str; } } class ParseTitle extends AsyncTask<Void, Void, HashMap<String,String>> 

{

  @Override protected HashMap<String, String> doInBackground(Void... voids) { HashMap<String, String> hashMap=new HashMap<>(); try { Document document = Jsoup.connect("http://ktits.ru").get(); Elements elements = document.select("div[class=news]").get(0).getElementsByTag("a"); for(Element element:elements) { hashMap.put(element.getElementsByClass("title").text(), element.attr("href")); } } catch (IOException e) { e.printStackTrace(); } return hashMap; } 

}

}

    1 answer 1

    They did it right when they attached a link to http://ktits.ru . And an empty window deduces that you did not assign a value locally to the variable str in your method.

     @Override protected String doInBackground(String... strings) { String str = ""; try { Document document = Jsoup.connect(strings[0]).get(); Elements elements = document.select("div[class=text]").get(0).getElementsByTag("p"); str = elements.first().ownText(); <-- вот }catch (IOException e){ e.printStackTrace(); } return str; } 

    UPD : And to avoid red tape with attaching a string in the ParseTitle class ParseTitle take not the href attribute itself, but its absolute url . From this

      hashMap.put(element.getElementsByClass("title").text(), element.attr("href")); 

    on this

      hashMap.put(element.getElementsByClass("title").text(), element.absUrl("href")); 
    • It seemed to me that he would take only what is written in the container ... Apparently, you need to reconsider the mat on jsoup. Thank you very much for the answer. - Domex pm
    • I recommend to “feel” everything in the debager quickly and clearly turns out, I myself work this way when it is not clear. - Krychun Ivan