title: Mapbox SDK in Android Fragment
body: <p>I want to show mapbox mapview in fragment but i cant do that. I looked lots of problems and solutions however i cant solve my issue. App is crashing always. BottomNavigation class is main class, MapFragment is fragment class which i want to see map. Also i attached Xml codes. Thank you!</p>
  
  <p>BottomNavigation.java</p>
  
  <pre class="lang-java prettyprint-override"><code>import android.os.Bundle;
  import android.support.annotation.NonNull;
  import android.support.design.widget.BottomNavigationView;
  import android.support.v4.app.Fragment;
  import android.support.v7.app.AppCompatActivity;
  import android.view.MenuItem;
  import android.widget.TextView;
  
  public class BottomNavigation extends AppCompatActivity implements BottomNavigationView.OnNavigationItemSelectedListener {
  
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_bottom_navigation);
  
  
          BottomNavigationView navigation = findViewById(R.id.navigation);
          navigation.setOnNavigationItemSelectedListener(this);
  
          loadFragment(new MapFragment());
  
      }
  
      private boolean loadFragment(Fragment fragment){
          if (fragment != null){
  
              getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,fragment).commit();
              return true;
  
          }
          return false;
  
      }
  
      @Override
      public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
  
          Fragment fragment = null;
  
          switch (menuItem.getItemId()){
  
              case R.id.navigation_map:
                  fragment = new MapFragment();
                  break;
              case R.id.navigation_search:
                  fragment = new SearchFragment();
                  break;
              case R.id.navigation_event:
                  fragment = new EventsFragment();
                  break;
              case R.id.navigation_profile:
                  fragment = new ProfileFragment();
                  break;
  
          }
  
          return loadFragment(fragment);
      }
  }
  </code></pre>
  
  <p>MapFragment.java</p>
  
  <pre><code>import android.content.Context;
  import android.net.Uri;
  import android.os.Bundle;
  import android.support.annotation.NonNull;
  import android.support.annotation.Nullable;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  import com.mapbox.mapboxsdk.Mapbox;
  import com.mapbox.mapboxsdk.camera.CameraPosition;
  import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
  import com.mapbox.mapboxsdk.geometry.LatLng;
  import com.mapbox.mapboxsdk.maps.MapView;
  import com.mapbox.mapboxsdk.maps.MapboxMap;
  import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
  import com.mapbox.mapboxsdk.maps.Style;
  
  public class MapFragment extends Fragment {
  
      private MapView mapView;
  
      public MapFragment(){
  
      }
  
      @Nullable
      @Override
      public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_map,container,false);
  
          mapView = (MapView) view.findViewById(R.id.mapview);
          mapView.onCreate(savedInstanceState);
          mapView.getMapAsync(new OnMapReadyCallback() {
              @Override
              public void onMapReady(@NonNull MapboxMap mapboxMap) {
                  mapboxMap.setStyle(new Style.Builder().fromUrl("mapbox://styles/orucbe/cjqnneisv0gns2ro1fy83ucgl"));
                  CameraPosition cameraPosition = new CameraPosition.Builder()
                          .target(new LatLng(41.885, -87.679)) // set the camera's center position
                          .zoom(12)  // set the camera's zoom level
                          .tilt(20)  // set the camera's tilt
                          .build();
  
                  // Move the camera to that position
                  mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
              }
          });
  
          return view;
      }
  
      @Override
      public void onResume() {
          super.onResume();
          mapView.onResume();
      }
  
      @Override
      public void onPause() {
          super.onPause();
          mapView.onPause();
      }
  
      @Override
      public void onSaveInstanceState(Bundle outState) {
          super.onSaveInstanceState(outState);
          mapView.onSaveInstanceState(outState);
      }
  
      @Override
      public void onLowMemory() {
          super.onLowMemory();
          mapView.onLowMemory();
      }
  
      @Override
      public void onDestroy() {
          super.onDestroy();
          mapView.onDestroy();
      }
  
  }
  </code></pre>
  
  <p>activity_bottom_navigation.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.constraint.ConstraintLayout 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:id="@+id/container"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".BottomNavigation"&gt;
  
      &lt;FrameLayout
          android:id="@+id/fragment_container"
          android:layout_width="0dp"
          android:layout_height="0dp"
          android:layout_marginBottom="56dp"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"&gt;
  
      &lt;/FrameLayout&gt;
  
  
      &lt;android.support.design.widget.BottomNavigationView
          android:id="@+id/navigation"
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_marginStart="0dp"
          android:layout_marginEnd="0dp"
          android:background="?android:attr/windowBackground"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintLeft_toLeftOf="parent"
          app:layout_constraintRight_toRightOf="parent"
          app:menu="@menu/navigation" /&gt;
  
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p>fragment_map.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.constraint.ConstraintLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      xmlns:mapbox="http://schemas.android.com/apk/res-auto"
      android:layout_height="match_parent"
      &gt;
  
  
      &lt;com.mapbox.mapboxsdk.maps.MapView
          android:id="@+id/mapview"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          &gt;
  
      &lt;/com.mapbox.mapboxsdk.maps.MapView&gt;
  
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>