Wednesday, 2 October 2013

Exception on calling getAdapter()

Exception on calling getAdapter()

LinkAdapter is a class which extends the ArrayAdapter.
private static List<LinkData> linkDataList = new ArrayList<LinkData>();
private LinkAdapter la;
la = new LinkAdapter(someLinkDataitmes, getActivity());
ListView lv = (ListView) v.findViewById(R.id.urls);
lv.setAdapter(la);
public class LinkData {
private String name, image, description;
public LinkData(String name, String image, String description){
this.name = name;
this.image=image;
this.description=description;
}
}
Now I later want to update my listview,
ListView lv = (ListView) v.findViewById(R.id.urls);
LinkAdapter mListAdapter = ((LinkAdapter)lv.getAdapter()); // this line is
giving an error.
mListAdapter.add(new LinkData(name_val, image_val, description_val));
mListAdapter.notifyDataSetChanged();
But the code is not working(giving a NullPointerException)
Searched a lot on the internet, but could not find a specific answer to my
problem.

1 comment: