This question already has an answer here:
we get trouble parsing live url using jsoup in android studio.the same code will be working in eclipse.we got the error
Method threw 'java.lang.NullPointerException' exception.can not evaluate org.jsoup.parser.HtmlTreebuilder.tostring()
here my activity code
String title=null;
Document document;
try {
document= Jsoup.connect("https://www.facebook.com/")
.userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
.referrer("http://www.google.com")
.get();
title=document.title();
TextView text=(TextView)findViewById(R.id.textView);
text.setText(title);
} catch (Exception e) {
e.printStackTrace();
Log.d("tag","document");
}
how to solve this issue and get the title from the live url?
you can use
AsyncTask
class to avoidNetworkOnMainThreadException
here you can try this code.}
and add your mainActivity this