Error rotating the screen with fragments 'open'

0

I'm using the simple fragment model. There is one List , and another Viewer . FragmentActivity :

    if(pFragVisualizar==null){
        pFragVisualizar = new FragVisualizar();
        pFragVisualizar.configuraVisualizador(dados);
    }
    if (!isPortrait()) {
        fragVisualizar = (FragVisualizar) getFragmentManager().findFragmentByTag("visualizar");
        fragVisualizar.configuraVisualizador(dados);
    }

Fragment :

public class FragVisualizar extends Fragment{

protected Dados dados;

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    return inflater.inflate( ((ActCadastro) getActivity()).visualizarID, container, false);
}

public void configuraVisualizador(Dados dados){
    this.dados= dados;
    if(getView()!=null) {
        dados.layout = getView().findViewById(R.id.cadastro_layout_principal);
        dados.atualizarViews();
        dados.restaurarEstado();
    }
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    if(dados!=null) {
        dados.layout = view.findViewById(R.id.cadastro_layout_principal);
        dados.atualizarViews();
        dados.restaurarEstado();
    }
}

}

When an item is selected in the list, it displays pFragView if it is in Vertical, or only changes the content of the DisplayView if it is horizontal. And it passes an instance of Data that puts the values in the views. On the vertical the onCreateView happens after the configuration of the Viewer, horizontally the opposite happens.

The problem is that if pFragView is visible, and the orientation is changed, it throws a strange very exception and is not helping me resolve the error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{minhaClasse}: android.view.InflateException: Binary XML file line #18: Binary XML file line #18: Error inflating class fragment
...
Caused by: java.lang.IllegalStateException: Fragment 'minhaClasse' did not create a view.

And even worse, after debugging I found that onCreateView occurs and the view is created normally, even though the error is shown before.

    
asked by anonymous 09.03.2016 / 15:50

0 answers