Skip to content Skip to sidebar Skip to footer

Listview Returning Null Using Fragment

When i try to retrieve the ListView coponent in XML layout, an NullPointerException is launched. ListView lv = (ListView) view.findViewById(R.id.lvAlerts); I'm using Fragments, a

Solution 1:

This is happening because you are using the wrong View variable to find the ListView.

ListViewlv= (ListView) view.findViewById(R.id.lvAlerts);

The view variable here refers to:

publicvoidonItemSelected(AdapterView<?> parent, View view, int pos, long id){

You need to refer to this view:

view = inflater.inflate(R.layout.tab_frag_alerts, container, false);

You should change the declaration:

Viewview;    //change viewtosome other name

Or,

publicvoidonItemSelected(AdapterView<?> parent, View someOtherView, int pos, long id){

Post a Comment for "Listview Returning Null Using Fragment"