getArguments () returns null!
code in action:
if (savedInstanceState == null) {
in fragment:
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mSearchParams = getArguments().getParcelable(SearchResultsActivity.EXTRA_SEARCH_PARAMS); return super.onCreateView(inflater, container, savedInstanceState); }
and
public static FlightListFragment newInstance(SearchParams sp) { FlightListFragment f = new FlightListFragment(); Bundle b = new Bundle(); b.putParcelable(SearchResultsActivity.EXTRA_SEARCH_PARAMS, sp); f.setArguments(b); return f; }
But I always get a NullPointerException here: getArguments ().
Please explain to me what I am doing wrong.
Thanks!
Editions:
I found that the newInstance () method is called after onCreateView, so I moved the code from it to onCreate, but the problem could not be avoided.
source share