Replacing the Fragment with another giving force close error while orientation is changed?
<p>In my application I have Fragments when i click on button 1, 2, 3 it will replaces the default fragment and view will be shown but when i change the orientation from Landscape to Portrait &amp; vice verse i am getting the force close error. I have two different layouts for landscape &amp; Portrait then also i am getting error. Below is my log-cat errors and my JAVA code, for replacing the fragments with another Fragment. I am not understanding what is the wrong in my code.  </p>

<pre><code>    01-08 06:57:54.689: E/AndroidRuntime(1616): FATAL EXCEPTION: main
    01-08 06:57:54.689: E/AndroidRuntime(1616): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.uwbt.ui/com.uwbt.ui.UWBTActivity}: java.lang.IllegalArgumentException: No view found for id 0x7f08005c (com.uwbt.ui:id/settings_fragment_holder) for fragment SettingsListFragment{410c8200 #5 id=0x7f08005c}
    01-08 06:57:54.689: E/AndroidRuntime(1616):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
    01-08 06:57:54.689: E/AndroidRuntime(1616):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
    01-08 06:57:54.689: E/AndroidRuntime(1616):     at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3351)
    01-08 06:57:54.689: E/AndroidRuntime(1616):     at android.app.ActivityThread.access$700(ActivityThread.java:123)
    01-08 06:57:54.689: E/AndroidRuntime(1616):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1151)
    01-08 06:57:54.689: E/AndroidRuntime(1616):     at android.os.Handler.dispatchMessage(Handler.java:99)
    01-08 06:57:54.689: E/AndroidRuntime(1616):     at android.os.Looper.loop(Looper.java:137)
    01-08 06:57:54.689: E/AndroidRuntime(1616):     at android.app.ActivityThread.main(ActivityThread.java:4424)
    01-08 06:57:54.689: E/AndroidRuntime(1616):     at java.lang.reflect.Method.invokeNative(Native Method)
    01-08 06:57:54.689: E/AndroidRuntime(1616):     at java.lang.reflect.Method.invoke(Method.java:511)
    01-08 06:57:54.689: E/AndroidRuntime(1616):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    01-08 06:57:54.689: E/AndroidRuntime(1616):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    01-08 06:57:54.689: E/AndroidRuntime(1616):     at dalvik.system.NativeStart.main(Native Method)
    01-08 06:57:54.689: E/AndroidRuntime(1616): Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f08005c (com.uwbt.ui:id/settings_fragment_holder) for fragment SettingsListFragment{410c8200 #5 id=0x7f08005c}
    01-08 06:57:54.689: E/AndroidRuntime(1616):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:903)
    01-08 06:57:54.689: E/AndroidRuntime(1616):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
    01-08 06:57:54.689: E/AndroidRuntime(1616):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
    01-08 06:57:54.689: E/AndroidRuntime(1616):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
    01-08 06:57:54.689: E/AndroidRuntime(1616):     at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:551)
    01-08 06:57:54.689: E/AndroidRuntime(1616):     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1133)
    01-08 06:57:54.689: E/AndroidRuntime(1616):     at android.app.Activity.performStart(Activity.java:4502)
    01-08 06:57:54.689: E/AndroidRuntime(1616):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1929)
    01-08 06:57:54.689: E/AndroidRuntime(1616):     ... 12 more
</code></pre>

<p>Here's my code :                    </p>

<pre><code> @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // TODO Auto-generated method stub

    if (getResources().getConfiguration().orientation ==
            Configuration.ORIENTATION_PORTRAIT) {
        Toast.makeText(getActivity(), "PORTRAIT", Toast.LENGTH_SHORT).show();
        view  = inflater.inflate(R.layout.settingsfragment, null);

    } else {
        Toast.makeText(getActivity(), "LandScape", Toast.LENGTH_SHORT).show();
        view  = inflater.inflate(R.layout.settingsfragment, null);
    }


    settingsStringArray = getResources().getStringArray(R.array.settingsScree_string_values);

    fragmentManager = getActivity().getSupportFragmentManager();
    fragmentTransaction = fragmentManager.beginTransaction();

    if (view.findViewById(R.id.settings_detail_holder) == null) {
        System.out.println("I am in smart phone");
        device = MOBILE;

        /**
         * It Will Load List Items in the panel Lefthandside
         */
        SettingsListFragment mSettingsFragment = new SettingsListFragment(this);
        fragmentTransaction.add(R.id.settings_fragment_holder,mSettingsFragment);

    } else {
        device = TABLET;

        /**
         * It Will Load List Items in the panel Lefthandside
         */
        SettingsListFragment mSettingsFragment = new SettingsListFragment(this);
        fragmentTransaction.add(R.id.settings_fragment_holder,mSettingsFragment);


        PairSensorFragment mPairSensor = new PairSensorFragment();
        fragmentTransaction.add(R.id.settings_detail_holder,mPairWithSensor);
    }

    fragmentTransaction.commit();

    return view;
}

@Override
public void onSettingItemClicked(String settings) {

    // Load the appropriate settings fragment
    passingValue = settings;  
    if (device == TABLET) {

        if (settings.equals(getString(R.string.settings_pairsensor))) {

            Log.d("","Inside "+settings);
            PairFragment mPairSensor = new PairFragment();
            fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.settings_detail_holder, mPairWithSensor);
            fragmentTransaction.commit();


        }else if (settings.equals(getString(R.string.settings_alarm))) {
            //
            if(preferences.getInt("condition_value", 0)==1)  
            {
                AlarmFragment mAlarmFragment = new AlarmFragment(this);
                fragmentTransaction = fragmentManager.beginTransaction();
                fragmentTransaction.replace(R.id.settings_detail_holder, mAlarmOffsetFragment);
                fragmentTransaction.commit();
            }else  
            {
                displayPairInfo();
            }
        }else if(settings.equals(getString(R.string.settings_restoredefault_settings)))//"Restore Default Settings" 
        {
            displayRestoreSettings();

        }else if (settings.equals(getString(R.string.settings_logging))) {//"Logging" 


            if(preferences.getInt("condition_value", 0)==1)
            {
                LoggFragment mLoggFragment = new LoggFragment(this);
                fragmentTransaction = fragmentManager.beginTransaction();
                fragmentTransaction.replace(R.id.settings_detail_holder,mLoggFragment);
                fragmentTransaction.commit();

            }else
            {
                displayPairInfo();
            }
        } else if (settings.equals(getString(R.string.settings_languages))) {//"Languages" 

            LangFragment mLangFragment = new LangFragment();   
            fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.settings_detail_holder,mLanguageFragment);
            fragmentTransaction.commit();

        }
    } else if (device == MOBILE) { 

        if (settings.equals(getString(R.string.settings_pairwithsensor))) {//"Pair With Sensor"
            // Load PairwithSensor fragment
            Log.d("","Inside "+settings);
            SensorFragment mSensor = new SensorFragment();
            fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.framelayout, mSensor);
            fragmentTransaction.commit();


        }else if (settings.equals(getString(R.string.settings_alarm))){

            if(preferences.getInt("condition_value", 0)==1)
            {
                //settingsDetailClass();
                AlarmFragment mAlarmFragment = new AlarmFragment(this);
                fragmentTransaction = fragmentManager.beginTransaction();
                fragmentTransaction.replace(R.id.framelayout, mAlarmFragment);
                fragmentTransaction.commit();

            }else{

                displayPairInfo();
            }
        }else if(settings.equals(getString(R.string.settings_restoredefault_settings)))
        {
            displayRestoreSettings();

        }else if (settings.equals(getString(R.string.settings_logging))) {
            //For to Load Logging fragment

            if(preferences.getInt("condition_value", 0)==1)
            {
                //settingsDetailClass();

                LoggFragment mLoggFragment = new LoggFragment(this);
                fragmentTransaction = fragmentManager.beginTransaction();
                fragmentTransaction.replace(R.id.framelayout,mLoggFragment);
                fragmentTransaction.commit();

            }else
            {
                displayPairInfo();
            }
        }else if (settings.equals(getString(R.string.settings_languages))) {//"Languages" 
            // Load Languages Fragment
            LangFragment mLangFragment = new LangFragment();   
            fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.framelayout,mLangFragment);
            fragmentTransaction.commit();

        }else if (settings.equals(getString(R.string.settings_save_all_settings))) {
            // Loads Dialog

            UWBTAlertDialog.showTitleAndMessageDialog(context, getString(R.string.saveall_settings_title) ,
                    getString(R.string.saveall_settings_message), getString(R.string.ok_value));

        }
    }

}

/*  public void settingsDetailClass()
{
    Intent mIntent = new Intent(getActivity(), SettingsDetailActivity.class);
    mIntent.putExtra("Settings", passingValue);
    startActivity(mIntent);
}
 */

/**
 * Alert Dialog For Restore Settings
 */
public void displayRestoreSettings()
{

    UWBTAlertDialog.showTitleAndMessageDialog(context, getString(R.string.restoredefault_settings_title) ,
            getString(R.string.restoredefault_settings_message), getString(R.string.ok_value));

}



public void displayPairInfo()
{

    UWBTAlertDialog.showTitleAndMessageDialog(context, getString(R.string.pws_noDevicePaired_title) ,
            getString(R.string.pws_noDevicePaired_message), getString(R.string.ok_value));

}  

@Override
public void onLoggingSettingsClicked(String logging) {
    // TODO Auto-generated method stub

}

@Override
public void onAlarmSettingsClicked(String alarmset) {
    // TODO Auto-generated method stub

}

@Override
public void onAttach(Activity activity) {
    // TODO Auto-generated method stub
    super.onAttach(activity);
}


@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    // Checks the orientation of the screen
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        setContentView(R.layout.settingsfragment);
        Toast.makeText(getActivity(), "Landscape", Toast.LENGTH_SHORT).show();

    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
        setContentView(R.layout.settingsfragment);
        Toast.makeText(getActivity(), "PORTRAIT", Toast.LENGTH_SHORT).show();
    }
}

private void setContentView(int settingsfragment) {
    // TODO Auto-generated method stub

}
</code></pre>
