Android: Listview Crashes
I'm using android listview and its working perfectly fine. my implementation as below ListView listview = (ListView)findViewById(R.id.list); setListAdapter(new ArrayAdapter
Solution 1:
Well from you code where you are using
setListAdapter(adapter);
indicates that you are using ListActivity
, and while using ListActivity
you get your list as follow:
listView = this.getListView();
or you can use
listView = this.findViewById(android.R.id.list);
and you are using
listView = this.findViewById(R.id.list);
which is wrong in case of ListActivity
, and ListView
cannot be found and results in NullPointerException
.
Solution 2:
Try like this.
Public classABCDimplementsOnItemClickListener{
ListView listview;//class varible
listview = (ListView)findViewById(R.id.list);
setListAdapter(newArrayAdapter<String>(MyIncidentActivity.this,
R.layout.row_incident, R.id.label_incident, db_results));
listview.setOnItemClickListener(this);
@OverridepublicvoidonItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
}
}
Post a Comment for "Android: Listview Crashes"