At the moment I have 14 elements added to an array list but I want them to be displayed in a listview activity so far I 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 I run this it will crash and I have no idea why as i have done this before using a simple array. If someone could point out what i'm doing wrong and give a solution that would be great thanks!