title: ClassCastException (Fragment cannot be cast to android.app.Activity)
body: <p><a href="https://i.stack.imgur.com/wqm3f.png" rel="nofollow noreferrer">Unable to instantiate activity Component, ClassCastExceptio</a>I'm new to android and so i followed different tutorials to accomplish my task. I'm having an error and despite all efforts it's still unable to resolve. I've a main activity through which i call a positive active(if user selects "yes" on alert). The positive activity basically contains a listView of three items and i want to display the contacts of mobile when user clicks on the first item. 
  I put the code of contacts retrieving in the fragment class but it's giving the error of casting even when i didn't use simple intent to call the fragment. 
  The code for main activity is as follows:</p>
  
  <pre><code>public class activity_home extends ActionBarActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_home);
      Context context = this;
      new AlertDialog.Builder(context)
              .setTitle("Alert")
              .setMessage("Do you want to enable the app right now?")
              .setPositiveButton("Yes", new DialogInterface.OnClickListener() 
  {
                   public void onClick(DialogInterface dialog,int id) {
                      // go to a new activity of the app
  
                      Intent positiveActivity = new 
  Intent(getApplicationContext(),
  
                              PositiveActivity.class);
  
                      startActivity(positiveActivity);
  
                  }
  
              })
  
      .setNegativeButton("No", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {
              // do nothing
          }
      })
  
  
              .setNeutralButton("Remind Me later", new 
  DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int 
  which) {
                              // do nothing
                          }
                      }
  
              )
  
  
              .
  
                      setIcon(android.R.drawable.ic_dialog_alert)
  
  
              .show();
  }}
  PositiveActivity.java:
  public class PositiveActivity extends FragmentActivity {
  ListView listView;
  ArrayList&lt;String&gt; listname;
  ArrayList&lt;String&gt; list_no;
  Context context;
  LayoutInflater inflater;
  
  
  @Override 
  protected void onCreate(Bundle savedInstanceState) {
  
  
  
  
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.positive_view);
      Context context = this;
      listView = (ListView) findViewById(R.id.mobile_list);
      TextView textView = new TextView(context);
      textView.setTypeface(null, Typeface.BOLD);
      textView.setHeight(100);
      textView.setText("Define Specifications for Enabling Auto Pickup!");
  
      listView.addHeaderView(textView);
  
  
      // Array of strings...
      String[] mobileArray = new String[] {"Add Numbers to the list","Select 
  Timer","Pick Selection Mode"};
  
  
      final ArrayAdapter &lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,
              android.R.layout.simple_list_item_1, android.R.id.text1, 
  mobileArray);
  
  
      listView.setAdapter(adapter);
  
      // ListView Item Click Listener
      listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                  int position, long id) {
  
              // ListView Clicked item index
              int itemPosition = position;
  
              // ListView Clicked item value
              String itemValue = (String) 
  listView.getItemAtPosition(position);
              if (itemPosition == 1) {
  
  
                 ContactListFragment fragmentS1 = new ContactListFragment();
  
  getSupportFragmentManager().beginTransaction().replace
  (R.id.headlines_fragment, 
  fragmentS1).commit();
  
  
              }}});}}
  
  And the code of Fragment:
  
  import android.support.v4.widget.SimpleCursorAdapter;
  
  public class ContactListFragment extends ListFragment implements 
  LoaderCallbacks&lt;Cursor&gt; {
  
  private CursorAdapter mAdapter;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      // create adapter once
      Context context = getActivity();
      int layout = android.R.layout.simple_list_item_1;
      Cursor c = null; // there is no cursor yet
      int flags = 0; // no auto-requery! Loader requeries.
      mAdapter = new SimpleCursorAdapter(context, layout, c, FROM, TO, flags);
  }
  
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
      super.onActivityCreated(savedInstanceState);
  
      // each time we are started use our listadapter
      setListAdapter(mAdapter);
      // and tell loader manager to start loading
      getLoaderManager().initLoader(0, null, this);
  }
  
  // columns requested from the database
  private static final String[] PROJECTION = {
          Contacts._ID, // _ID is always required
          Contacts.DISPLAY_NAME_PRIMARY // that's what we want to display
  };
  
  // and name should be displayed in the text1 textview in item layout
  private static final String[] FROM = { Contacts.DISPLAY_NAME_PRIMARY };
  private static final int[] TO = { android.R.id.text1 };
  
  @Override
  public Loader&lt;Cursor&gt; onCreateLoader(int id, Bundle args) {
  
      // load from the "Contacts table"
      Uri contentUri = Contacts.CONTENT_URI;
  
      // no sub-selection, no sort order, simply every row
      // projection says we want just the _id and the name column
      return new CursorLoader(getActivity(),
              contentUri,
              PROJECTION,
              null,
              null,
              null);
  }
  
  @Override
  public void onLoadFinished(Loader&lt;Cursor&gt; loader, Cursor data) {
      // Once cursor is loaded, give it to adapter
      mAdapter.swapCursor(data);
  }
  
  @Override
  public void onLoaderReset(Loader&lt;Cursor&gt; loader) {
      // on reset take any old cursor away
      mAdapter.swapCursor(null);
  }
  }
  </code></pre>
  
  <p>I'll be  grateful if someone points out the mistake in code</p>