Reputation: 25
Trying to get text value of child in expandableListView.
Getting a nullpointerexception in the onchildclick event.
E/AndroidRuntime(358): at tournament.tracker.pkg.ExpList$5.onChildClick(ExpList.java:124)
Line 124 is the adapter.getChild
line.
I'm trying to pass the string value of the child that is clicked to another activity.
expList.setOnChildClickListener(new OnChildClickListener()
{
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
ExpandableListAdapter adapter = getExpandableListAdapter();
gametype = adapter.getChild(groupPosition, childPosition).toString();
//---------------------
Intent pullt = new Intent(ExpList.this, JsonActivity.class);
Bundle bundle = new Bundle();
bundle.putString("gametype", gametype);
pullt.putExtras(bundle);
pullt.putExtra("gametype", gametype);
startActivity(pullt);
//---------------------
return false;
}
});
Anyone know why this is not working? Please help if possible
EDIT
Here's the adapter:
public class ExpAdapter extends BaseExpandableListAdapter {
private Context myContext;
public ExpAdapter(Context context) {
myContext = context;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return null;
}
// Other code - not relevant
}
Upvotes: 0
Views: 259
Reputation: 86958
public Object getChild(int groupPosition, int childPosition) {
return null;
}
This function will always return null. Trying to access null in any way (like using toString()
) will create a Null Pointer Exception, you must implement this function to return actual data.
A fix may possibly be:
public Object getChild(int groupPosition, int childPosition) {
return ExpList.arrChildelements[groupPosition][childPosition];;
}
Upvotes: 3