title: unable to load fragment from activity
body: <p>I am using Sherlock Fragments library to sliding menu.my problem is i unable to load fragment when i click button in activity. I am getting java.lang.classcastException
  to android.app.activity.</p>
  
  <p>I have imported:</p>
  
  <pre><code>import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentActivity;
  </code></pre>
  
  <p>but still I am getting error.</p>
  
  <p>code for mainActivity.</p>
  
  <pre><code>public class AmecmainActivity extends FragmentActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
  
        actionnetwork=(ImageButton)findViewById(R.id.ActionNetwork);
        actionnetwork.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
          Intent action=new Intent(v.getContext().getApplicationContext(),
                  Fragment2.class);
          startActivity(action);  
  
          }
      });
  </code></pre>
  
  <p>and code in fragment2 </p>
  
  <pre><code>public class Fragment2 extends Fragment{
  
      Fragment fragment;
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      View view = inflater.inflate(R.layout.actionnetworklogin, container, false);
      Button login = (Button)view.findViewById(R.id.login);
      login.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
                });
      } 
  return view;
  </code></pre>
  
  <p>can any one help me </p>
  
  <p>framelayout xml</p>
  
  <pre><code>   &lt;?xml version="1.0" encoding="utf-8"?&gt;
            &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:orientation="vertical" &gt;
  
            &lt;FrameLayout
             android:id="@+id/fragment_container"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:background="?android:attr/detailsElementBackground" /&gt;
  
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>onclick method :</p>
  
  <pre><code>  actionnetwork=(ImageButton)findViewById(R.id.ActionNetwork);
    actionnetwork.setOnClickListener(new OnClickListener() {
  
      @Override
      public void onClick(View v) {
            Fragment fragment = new Fragment2();
            FragmentManager fm =getSupportFragmentManager();
            FragmentTransaction transaction = fm.beginTransaction();
            transaction.replace(R.id.fragment_container, fragment); 
            transaction.commit(); 
      }
  });
  
  
  
    fragment2 xml
  
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/LinearLayout1"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="#ffffff" &gt;
  
  &lt;TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_centerVertical="true"
      android:text="Second Fragment"
      android:textSize="15pt" /&gt;
  
      &lt;/RelativeLayout&gt;
  
  
  
  mainactivity:
  
    &lt;?xml version="1.0" encoding="utf-8"?&gt;
    &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="wrap_content"
     android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
  
     &lt;LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal"
      android:scaleType="fitXY" &gt;
  
           &lt;ImageButton
              android:id="@+id/ActionNetwork"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginTop="28dp"
              android:layout_marginLeft="25dp"
              android:src="@drawable/ic_launcher" /&gt;
  
  &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>code for pervious fragment</p>
  
  <pre><code>      public boolean onOptionsItemSelected(MenuItem item) 
      {
      switch (item.getItemId()) 
      {
      case R.id.menuIcon:
           toggle();
           break; 
       case android.R.id.home:
  
           getFragmentManager().popBackStackImmediate();
                              }
      return super.onOptionsItemSelected(item);
  }
  </code></pre>
  
  <p>fragment2.class file</p>
  
  <p>public class Fragment1 extends Fragment {</p>
  
  <pre><code>public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.fragment1, container, false);
      Button clicked=(Button)view.findViewById(R.id.clickedmove);
      clicked.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
                Fragment fragment = new Fragment2();
                FragmentManager fm =getFragmentManager();
                FragmentTransaction transaction = fm.beginTransaction();
                transaction.addToBackStack(null);
                transaction.replace(R.id.contentFragment, fragment); 
                transaction.commit(); 
          }
      });
      return view;
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
  }
  </code></pre>
  
  <p>}</p>