getArguments() は null を返します!
活動中のコード:
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();
}
断片的に:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
mSearchParams =
getArguments().getParcelable(SearchResultsActivity.EXTRA_SEARCH_PARAMS);
return super.onCreateView(inflater, container, savedInstanceState);
}
と:
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;
}
しかし、私は常にここで NullPointerException を取得します: getArguments()。
私が間違っていることを説明してください。
ありがとう!
編集:
newInstance() メソッドが onCreateView の後に呼び出されることがわかったので、コードをそこから onCreate に移動しましたが、問題は回避されませんでした。