目前我有 14 个元素添加到数组列表中,但我希望它们显示在 listview 活动中,到目前为止我有:
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");
}
}
}
但是,每次我运行它都会崩溃,我不知道为什么我在使用简单数组之前已经这样做了。如果有人能指出我做错了什么并提供解决方案,那将非常感谢!