title: getSupportFragmentManager().findFragmentById() returns null
body: <p>I am trying to implement fragment communication in android like the one in the android guide <a href="http://developer.android.com/guide/components/fragments.html#CommunicatingWithActivity">http://developer.android.com/guide/components/fragments.html#CommunicatingWithActivity</a></p>
  
  <p>but my application is crashing as the  getSupportFragmentManager().findFragmentById() returns null. What is the issue with my implementation.</p>
  
  <p>The code is given below:</p>
  
  <p>The program is just to send an input text from one fragment to another fragment textView area through a button click from first fragmnet.I have an activity_main.xml and two fragment layout (two separate xml files rather than part of  in activity_main.xml)</p>
  
  <p>Frag1.java</p>
  
  <pre><code>public class Frag1 extends Fragment {
  public Frag1(){
  
  }
  
  buttonClickListener buttonListener;
  
  @Override
  public void onAttach(Activity activity) {
  super.onAttach(activity);
  try {
      buttonListener = (buttonClickListener) getActivity();
  } catch (ClassCastException e) {
      throw new ClassCastException(activity.toString() + " must implement OnButtonPressListener");
  }
  }
  
  View myFragmentView;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      myFragmentView = inflater.inflate(R.layout.frag1, container, false);
  
  
      //SetValue Button
      Button setValueButton = (Button) myFragmentView.findViewById(R.id.setValueButton);
      setValueButton.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              buttonListener.onButtonPressed("Message received");
          }
      });
  
  
      return myFragmentView;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Frag2.java </p>
  
  <pre><code>public class Frag2 extends Fragment {
  
  View myFragmentView;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
   myFragmentView = inflater.inflate(R.layout.frag2, container, false);
      return myFragmentView;
  }
  
  void setMessage(String msg){
      TextView txt=(TextView)myFragmentView.findViewById(R.id.textView1);
      txt.setText(msg);
  }
  }
  </code></pre>
  
  <p>buttonClickListener.java</p>
  
  <pre><code>public interface buttonClickListener {
  public void onButtonPressed(String msg);
  }
  </code></pre>
  
  <p>MainActivity.java</p>
  
  <pre><code>public class MainActivity extends FragmentActivity implements
      ActionBar.TabListener, buttonClickListener {
  SectionsPagerAdapter mSectionsPagerAdapter;
  @Override
  public void onButtonPressed(String msg) {
      // TODO Auto-generated method stub
      Frag2 fragmentObj=(Frag2) getSupportFragmentManager().findFragmentById(R.layout.frag2);
  
  
      fragmentObj.setMessage(msg);
  }
  </code></pre>
  
  <p>Please tell me where did I go wrong?</p>
  
  <p>EDIT: 
  I am using fragment creation using the template generated by Android Plug-in eclipse IDE.
  So the fragments are created using <strong>android.support.v4.app.Fragment</strong></p>
  
  <pre><code>@Override
      public Fragment getItem(int position) {
          Fragment fragment = null;
          switch(position)
          {
          case 0:
              return new Frag1();
          case 1: 
              return new Frag2();
          }
          return fragment;
      }
  </code></pre>
  
  <p>The codebase is kept here for reference
  <a href="https://skydrive.live.com/redir?resid=D37E0F56FEC9B499!259">https://skydrive.live.com/redir?resid=D37E0F56FEC9B499!259</a></p>