title: Error: incompatible types: android.support.v4.app.Fragment cannot be converted to android.app.Fragment
body: <p>Before i ask this question i have tried all available options and solutions provided here to no  avail. Learning to create fragments with this link   <a href="https://abhiandroid.com/ui/fragment" rel="nofollow noreferrer">https://abhiandroid.com/ui/fragment</a>. There are two fragment classes in 
  addition to MainActivity. The two fragment classes throw no error, but 
  MainActivity at this line does </p>
  
  <pre><code>fragmentTransaction.replace(R.id.frameLayout, fragment); 
  </code></pre>
  
  <p>under this method. The argument "fragment" is underlined in red</p>
  
  <pre><code>private void loadFragment(Fragment fragment) {
  // create a FragmentManager
      FragmentManager fm = getFragmentManager();
  // create a FragmentTransaction to begin the transaction and replace the 
  //Fragment
      FragmentTransaction fragmentTransaction = fm.beginTransaction();
  // replace the FrameLayout with new Fragment
      fragmentTransaction.replace(R.id.frameLayout, fragment);
      fragmentTransaction.addToBackStack(null);
      fragmentTransaction.commit(); // save the changes
  }
  </code></pre>
  
  <p>The error message says 
   Wrong 2nd argument type. Found android.support.v4.app.Fragment required 
   android.app.Fragment </p>
  
  <p>when i hover with my mouse and if rebuild, i have this</p>
  
  <p>Error:(51, 55) error: incompatible types: android.support.v4.app.Fragment 
   cannot be converted to android.app.Fragment</p>
  
  <p>For clarity sake, i add the codes</p>
  
  <p>MainActivity XML</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      tools:context=".MainActivity"&gt;
      &lt;!-- display two Button's and a FrameLayout to replace the Fragment's  --&gt;
      &lt;Button
          android:id="@+id/firstFragment"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="@color/button_background_color"
          android:text="First Fragment"
          android:textColor="@color/white"
          android:textSize="20sp" /&gt;
  
      &lt;Button
          android:id="@+id/secondFragment"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="10dp"
          android:background="@color/button_background_color"
          android:text="Second Fragment"
          android:textColor="@color/white"
          android:textSize="20sp" /&gt;
  
      &lt;FrameLayout
          android:id="@+id/frameLayout"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_marginTop="10dp" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>MainActivity</p>
  
  <p>package com.example.android.fragmentexample;</p>
  
  <pre><code>import android.support.v4.app.Fragment;
  import android.app.FragmentManager;
  import android.app.FragmentTransaction;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  
  public class MainActivity extends AppCompatActivity {
  
      Button firstFragment, secondFragment;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          Fragment fragment = new Fragment();
  
  // get the reference of Button's
          firstFragment = (Button) findViewById(R.id.firstFragment);
          secondFragment = (Button) findViewById(R.id.secondFragment);
  
  // perform setOnClickListener event on First Button
          firstFragment.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  // load First Fragment
                  loadFragment(new FirstFragment());
              }
          });
  // perform setOnClickListener event on Second Button
          secondFragment.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  // load Second Fragment
                  loadFragment(new SecondFragment());
              }
          });
  
      }
  
      private void loadFragment(Fragment fragment) {
  // create a FragmentManager
          FragmentManager fm = getFragmentManager();
  // create a FragmentTransaction to begin the transaction and replace the 
   //Fragment
          FragmentTransaction fragmentTransaction = fm.beginTransaction();
  // replace the FrameLayout with new Fragment
          fragmentTransaction.replace(R.id.frameLayout, fragment);
          fragmentTransaction.addToBackStack(null);
          fragmentTransaction.commit(); // save the changes
      }
  }
  
   FirstFragment xml
  
  &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="com.example.android.fragmentexample.FirstFragment"&gt;
  
      &lt;!-- TODO: Update blank fragment layout --&gt;
     &lt;RelativeLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"&gt;
         &lt;!--TextView and Button displayed in First Fragment --&gt;
         &lt;TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_centerHorizontal="true"
             android:layout_marginTop="100dp"
             android:text="This is First Fragment"
             android:textColor="@color/black"
             android:textSize="25sp" /&gt;
  
         &lt;Button
             android:id="@+id/firstButton"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:layout_centerInParent="true"
             android:layout_marginLeft="20dp"
             android:layout_marginRight="20dp"
             android:background="@color/green"
             android:text="First Fragment"
             android:textColor="@color/white"
             android:textSize="20sp"
             android:textStyle="bold" /&gt;
  
     &lt;/RelativeLayout&gt;
  
  &lt;/FrameLayout&gt;
  
  FirstFragment.java
  
  package com.example.android.fragmentexample;
  
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.Button;
  import android.widget.Toast;
  /**
   * A simple {@link Fragment} subclass.
   */
  public class FirstFragment extends Fragment {
  
      View view; Button firstButton;
  
  //    public FirstFragment() {
  //        // Required empty public constructor
  //    }
  
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          view = inflater.inflate(R.layout.fragment_first, container, false);
          //get the reference of the FirstButton
          firstButton = view.findViewById(R.id.firstButton);
          //perform setOnClickListener on the firstButton
          firstButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) { 
                    //display a message by using a toast
                  Toast.makeText(getActivity(), "First Fragment", 
                  Toast.LENGTH_SHORT).show();
  
  
              }
          });
  
          return view;
      }
  
  }
  </code></pre>
  
  <p>The secondFragment class and xml files are similar to the FirstFragment class and xml files only change of neames where necessary distinguish it from the other</p>