android - How do you display an arrayList in a ListView? -


at moment have 14 elements added array list want them displayed in listview activity far have:

public class listview extends listactivity{    static final string baseurl ="http://www.dublincity.ie/dublintraffic/cpdata.xml?1354720067473";   textview tvcp;    @override   protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.listview);     stringbuilder url = new stringbuilder(baseurl);     string fullurl = url.tostring();     try{       url website = new url(fullurl);       saxparserfactory spf = saxparserfactory.newinstance();       saxparser sp = spf.newsaxparser();       xmlreader xr = sp.getxmlreader();       handelingxml gettingdata = new handelingxml();       xr.setcontenthandler(gettingdata);       xr.parse(new inputsource(website.openstream()));        arraylist<carparknode>carparks = gettingdata.getcarparks();        this.setlistadapter(         new arrayadapter<carparknode>(listview.this,r.layout.listview, android.r.id.list, carparks)       );     }catch(exception e){       tvcp.settext("error");     }   } } 

however, every time run crash , have no idea why have done before using simple array. if point out i'm doing wrong , give solution great thanks!

first don't give class name listview predefined class in android

second don't perform network operation on ui thread.

edit:

reason:

android version 3.x or more devices won't allow network operation perform in ui thread, when try throw exception saying performing network operation on ui thread, i.e networkonmainthreadexception. need create separate thread execute network operation or asynctask.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -