我有一个扩展DialogFragment的CustomDialog类。我想从我的适配器获取ArrayList。我有这个例外java.lang.NullPointerException:尝试调用虚方法' java.io.Serializable android.os.Bundle.getSerializable(java.lang.String)'我尝试运行时在空对象引用上。
holder.choisirButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int positionselected = menuItem.getId();
Bundle bundle = new Bundle();
bundle.putSerializable("menuItemList", menuItemList);
bundle.putInt("positionselected", positionselected);
FragmentActivity activity = (FragmentActivity) (context);
FragmentManager fm = activity.getFragmentManager();
ComplementFragment alertDialog = new ComplementFragment();
alertDialog.show(fm, "fragment_alert");
}
});
public class ComplementFragment extends DialogFragment {
ArrayList<MenuItem> menuItemsList;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.custom_dialog_layout, container);
menuItemList = (ArrayList<MenuItem>) getArguments().getSerializable("menuItemList");
int selectedPosition = getArguments().getInt("positionselected");
MenuItem menuItem = menuItemList.get(selectedPosition);
return view;
}
}