getArguments() return null!
code in activity:
if (savedInstanceState == null) {
// During initial setup, plug in the details fragment.
FlightListFragment listFragment =
FlightListFragment.newInstance(mSearchParams);
getSupportFragmentManager().beginTransaction().add(
android.R.id.content, listFragment).commit();
}
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 NullPointerException here: getArguments().
Please, explain me what I am doing wrong.
Thanks!
EDITED:
I've found that newInstance() method is called after onCreateView, so I moved code from it to onCreate, but the issue didn't avoid.
It means no arguments were supplied when the fragment was instantiated...
you can check if arguments were supplied by doing something like this...
Bundle arguments = getArguments();
if (arguments != null)
{
// then you have arguments
} else {
// no arguments supplied...
}
OK - I misread your question...
Is sp null at the point your doing putParcelable?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With