尝试在expandableListView中获取子项的文本值。onChildClick获取nullpointerexception
在onchildclick事件中获取nullpointerexception。
E/AndroidRuntime(358): at tournament.tracker.pkg.ExpList$5.onChildClick(ExpList.java:124)
124行是adapter.getChild
行。
我想传递被点击到另一个活动的孩子的字符串值。
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;
}
});
任何人都知道为什么这不起作用?请帮助如果可能的话
编辑
这里的适配器:
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
}
究竟是怎样的例外是什么样子? (又名:stacktrace plz!) – yoshi
你在哪里得到NullPointerException? –
快速猜测只有'适配器'将是一个可能的候选人。所以'getExpandableListAdapter()'返回'null'。你有没有设置适配器? – yoshi