title: Attach a Fragment to the Activity
body: <p>I am trying to attach a Fragment to my MainActivity programmatically by using the following code:  </p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      FragmentManager fragmentManager = getFragmentManager();
      FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
      MainFragment fragment = new MainFragment();
      fragmentTransaction.add(R.id.activity_main,fragment);
      fragmentTransaction.commit();
  
  
  }
  </code></pre>
  
  <p>it gives me an error: <code>cannot resolve add method</code></p>
  
  <p>The application can be found <a href="https://github.com/MoaadGit/Weather" rel="nofollow noreferrer">here</a></p>