dimanche 20 septembre 2015

JSOUP Does not work

im trying to get the title of random wikipedia articles and view them at a listview

http://ift.tt/NBwXxT this link returns random wiki article

here is my code :

final ListView listview = (ListView) findViewById(R.id.container);
    String []vals = new String[4];
    for(int i = 0 ; i < 4 ; i++)
    {
        try {
            Document doc = Jsoup.connect("http://ift.tt/NBwXxT").get() ;
            vals[i] = doc.title();
        }catch(IOException e){}
    }
    final ArrayList<String> List = new ArrayList<>() ;
    for(int i = 0 ; i < vals.length ; i++)
        List.add(vals[i]);
    final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this , android.R.layout.simple_expandable_list_item_1 , List) ;
    listview.setAdapter(adapter);

but when i run my code at the emulator the app crashs , any idea??




Aucun commentaire:

Enregistrer un commentaire