onCaveInstanceState()在onCreateView()之前调用?

时间:2017-03-06 14:31:21

标签: android android-fragments

我正在使用android数据绑定,我正在将我的片段的布局扩展为全局binding变量,其中包含:

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {
    binding = MyFragmentBinding.inflate(inflater, container, false);
    return binding.getRoot();
}

我收到了一些nullpointer崩溃事件,指向这一行的崩溃分析:

@Override
public void onSaveInstanceState(Bundle outState) {
    binding.mapView.onSaveInstanceState(outState);
}

错误是: Caused by java.lang.NullPointerException: Attempt to read from field 'com.google.android.gms.maps.MapView net.kjulio.myapp.databinding.MyFragmentBinding.mapView' on a null object reference;

为什么这样?在我看来,只有在onSaveInstanceState()之前调用onCreateView()时才可能这样做。这可能吗?

0 个答案:

没有答案