title: runtimeexception:unable to destroy activity and RuntimeException:.nosuchfieldexception: mChildfragmentManager
body: <p>I'm really having a hard time figuring this out. When I looked where the logcat points the error, it points to this line:</p>
  
  <pre><code>throw new RuntimeException(i);
  </code></pre>
  
  <p>inside this </p>
  
  <pre><code>public void onDetach() {
      super.onDetach();
      try {
          Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager");
          childFragmentManager.setAccessible(true);
          childFragmentManager.set(this, null);
      } catch (NoSuchFieldException i) {
          throw new RuntimeException(i);
      } catch (IllegalAccessException i) {
          throw new RuntimeException(i);
      }
  }
  </code></pre>
  
  <p>This happens when I changed to landscape orientation. I know the view is being recreated after a change of orientation, I was able to do this on my Google maps also in this app, but I don't know how to implement it on a webview. I have a webview that shows facebook sharer.php and when I change it to landscape orientation, it force stops. </p>
  
  <p>This is my code for this tab:</p>
  
  <pre><code>public class TabFour extends Fragment {
  
  static WebView webView;
  String myBlogAddr = "http://192.168.1.75/Treasuria-v2/";
  String myUrl;
  Button map;
  View rootView;
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      rootView = inflater.inflate(R.layout.activity_tab_four, container, false);
  
      displayWebview();
      return rootView;
  
  
  }
  
  protected void displayWebview(){
  webView= (WebView)rootView.findViewById(R.id.webView);
  
  
      webView.setWebViewClient(new MyWebViewClient());
      String title = "Quezon City Guide";
      String desc = "Your Number One City Guide!";
      String image = "http://s22.postimg.org/5t4qidqpt/launcher114x114.png";
  
      myBlogAddr ="http://www.facebook.com/sharer.php?m2w&amp;s=100&amp;p[title]="+title+"&amp;p[summary]="+desc+"&amp;p[url]=http://www.sample.com&amp;p[images][0]="+image;
      if(myUrl == null){
          myUrl = myBlogAddr;
      }
      webView.loadUrl(myUrl);
      Log.i("URL", myBlogAddr);
  
      map = (Button) rootView.findViewById(R.id.buttonMap);
  
      map.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {
  
              getActivity().getActionBar().setSelectedNavigationItem(2);
          }
      });
  }
  
  private class MyWebViewClient extends WebViewClient {
      @Override
      public boolean shouldOverrideUrlLoading(WebView view, String url) {
          myUrl = url;
          view.loadUrl(url);
          return true;
      }
  }
  
  
  public void onBackPressed() {
      if(webView.canGoBack())
          webView.goBack();
  }
  
  public void OnCreate(Bundle savedInstanceState){
      super.onCreate(savedInstanceState);
      getActivity().getActionBar().setSelectedNavigationItem(1);
      map = (Button) rootView.findViewById(R.id.buttonMap);
  
      map.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {
  
              getActivity().getActionBar().setSelectedNavigationItem(2);
          }
      });
  }
  
  @Override
  public void onConfigurationChanged(Configuration newConfig) {
      // TODO Auto-generated method stub
      super.onConfigurationChanged(newConfig);
  }
  
  
  public void onDetach() {
      super.onDetach();
      try {
          Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager");
          childFragmentManager.setAccessible(true);
          childFragmentManager.set(this, null);
      } catch (NoSuchFieldException i) {
          throw new RuntimeException(i);
      } catch (IllegalAccessException i) {
          throw new RuntimeException(i);
      }
  }
  
  }
  </code></pre>
  
  <p><strong>GoogleMap Tab</strong></p>
  
  <pre><code>public class TabTwo extends Fragment {
  
  private static View view;
  
  private static GoogleMap map;
  private static Double latitude, longitude;
  private static LatLngBounds QC = new LatLngBounds(
        new LatLng(14.656669, 120.998598), new LatLng(14.666965, 121.098934));
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
  
      view = inflater.inflate(R.layout.activity_tab_two, null);
      // Passing hard coded values for latitude &amp; longitude. Please change as per your need. This is just used to drop a Marker on the Map
              latitude = 14.6353475;
              longitude = 121.0327501;
              map = ((SupportMapFragment) MainActivity.fragmentManager
                      .findFragmentById(R.id.map)).getMap();
              setUpMapIfNeeded(); // For setting up the MapFragment
  
      return view;
  }
  
  /***** Sets up the map if it is possible to do so *****/
  public static void setUpMapIfNeeded() {
      // Do a null check to confirm that we have not already instantiated the map.
      if (map == null) {
          // Try to obtain the map from the SupportMapFragment.
          map = ((SupportMapFragment) MainActivity.fragmentManager
                  .findFragmentById(R.id.map)).getMap();
          // Check if we were successful in obtaining the map.
          if (map != null)
              setUpMap();
      }
  }
  
  /**
   * This is where we can add markers or lines, add listeners or move the
   * camera.
   * &lt;p&gt;
   * This should only be called once and when we are sure that {@link #mMap}
   * is not null.
   */
  private static void setUpMap() {
      // For showing a move to my location button
       map = ((SupportMapFragment) MainActivity.fragmentManager
                  .findFragmentById(R.id.map)).getMap();
      map.setMyLocationEnabled(true);
      map.getUiSettings().setCompassEnabled(true);
      map.getUiSettings().setRotateGesturesEnabled(true);
      // For dropping a marker at a point on the Map
      map.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title("Estuar Building").snippet("Work Place"));
      // For zooming automatically to the Dropped PIN Location
      map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude,
              longitude), 12.0f));
      map.moveCamera(CameraUpdateFactory.newLatLngZoom(QC.getCenter(), 12));
  }
  
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      if (map != null)
          setUpMap();
  
      if (map == null) {
          // Try to obtain the map from the SupportMapFragment.
          map = ((SupportMapFragment) MainActivity.fragmentManager
                  .findFragmentById(R.id.map)).getMap();
          // Check if we were successful in obtaining the map.
          if (map != null)
              setUpMap();
      }
  }
  
  /**** The mapfragment's id must be removed from the FragmentManager
   **** or else if the same it is passed on the next time then 
   **** application will crash ****/
  @Override
  public void onDestroyView() {
      super.onDestroyView();
      try {
          Fragment fragment = (getFragmentManager().findFragmentById(R.id.map));  
          FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
          ft.remove(fragment);
          ft.commit();
          setUpMap();
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  
  public void onDetach() {
      super.onDetach();
      try {
          Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager");
          childFragmentManager.setAccessible(true);
          childFragmentManager.set(this, null);
      } catch (NoSuchFieldException i) {
          throw new RuntimeException(i);
      } catch (IllegalAccessException i) {
          throw new RuntimeException(i);
      }
  }
   }
  </code></pre>
  
  <p>Please help. Thanks!</p>