I want to get links in a address, and I use Jsoup
and RecyclerView
, so I do this:
public static List<News> newsList(String url) {
List<News> newsArrayList = new ArrayList<>();
try {
Document document = Jsoup.connect().get();
Elements newsElements = document.select(".boxMiddle .grpLinks a");
int i = 1;
for (Element newsElement : newsElements) {
News news = new News();
news.setId(i);
news.setTitle(newsElement.text());
news.setDate(newsElement.attr("title"));
news.setUrl(Uri.parse("www.google.com"));
newsArrayList.add(news);
i++;
}
} catch (IOException e) {
e.printStackTrace();
}
return newsArrayList;
}
However, I get this error: android.os.NetworkOnMainThreadException
!
How can I solve this error?