Im getting a null pointer exception when I attempt to get an array of image urls using jsoup, really not sure what Im doing wrong here as I appears that Im following the example layed out in the javadoc, any help would go a long way thanks.
public class ImagetestActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String url = "http://www.goal.com/en/news/1717/editorial/2012/05/20/3116140/in-pictures-chelsea-celebrate-champions-league-success#";
Document doc = null;
List<Element> media = new ArrayList<Element>();
try {
doc = Jsoup.connect(url).get();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
media = doc.select("[src]");
for (Element src : media) {
if (src.tagName().equals("img")) {
Toast.makeText(ImagetestActivity.this, src.text(),
Toast.LENGTH_LONG).show();
}
}
}
}
Try this:
I.e. select images (no need to check the tag name). And probably you need src attribute value, not inner text (which is always empty)