title: How to add a Fragment with a different class to my MainActivity
body: <p>I'm working on adding a fragment to my Main Activity which will show a Google Map.</p>
  
  <p>What I want to achieve? </p>
  
  <ul>
  <li>I want the added fragment to have another corresponding Java class to it. </li>
  </ul>
  
  <p>This is the xml file for my MainActivity.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="com.jovan.APPNAME.MainActivity"&gt;
  
      &lt;android.support.v7.widget.Toolbar
          android:layout_width="match_parent"
          android:layout_height="?attr/actionBarSize"
          android:id="@+id/toolbar"
          android:background="?attr/colorPrimaryDark"
          app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/&gt;
  
      &lt;fragment
          android:id="@+id/map"
          android:layout_below="@+id/toolbar"
          android:name="com.google.android.gms.maps.SupportMapFragment"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          tools:context="com.jovan.APPNAME.MapsActivity" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>I want the fragment to have a it's own java class. This is the Java class. </p>
  
  <pre><code>public class MapsActivity extends Fragment implements OnMapReadyCallback {
  
      private GoogleMap mMap;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
      }
  
      @Nullable
      @Override
      public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.activity_main, container, false);
          SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
          mapFragment.getMapAsync(this);
          return view;
      }
  
  
      @Override
      public void onMapReady(GoogleMap googleMap) {
          mMap = googleMap;
  
          // Add a marker in Sydney and move the camera
          LatLng sydney = new LatLng(-34, 151);
          mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
          mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
      }
  }
  </code></pre>
  
  <p>Here is also the Java class for the Main Activity. </p>
  
  <pre><code>public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
  
      Toolbar toolbar;
      DrawerLayout drawerLayout;
      NavigationView navigationView;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.navigation_drawer);
  
          setTitle("");
  
          toolbar = (Toolbar) findViewById(R.id.toolbar);
          drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
          navigationView = (NavigationView) findViewById(R.id.navigation_view);
  
          setSupportActionBar(toolbar);
          navigationView.setNavigationItemSelectedListener(this);
          ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open_drawer, R.string.close_drawer);
          drawerLayout.setDrawerListener(toggle);
          toggle.syncState();
  
  
      }
  
      @Override
      public void onBackPressed() {
          if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
              drawerLayout.closeDrawer(GravityCompat.START);
          } else {
              super.onBackPressed();
          }
  
      }
  
      @Override
      public boolean onNavigationItemSelected(@NonNull MenuItem item) {
  
          int id = item.getItemId();
  
          switch (id) {
  
  
          }
  
          drawerLayout.closeDrawer(GravityCompat.START);
          return true;
      }
  }
  </code></pre>
  
  <p>However as it is right now it does not work. I assume that the fragment isn't found. Any idea how i can fix this and make it work. Thanks in advice. </p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I suspect that my fragment and the class aren't wired up property.
  I tried to make all the changes that are provided by the answers but then I got a black screen. </p>