Home » Java » Load map fragment with list of markers in bottom navigation drawer

Load map fragment with list of markers in bottom navigation drawer

Posted by: admin August 10, 2018 Leave a comment

Questions:

In my apllication i use bottom navigation view. In the third fragment must be map. And i don`t know how to send data in this fragment.

Method in ActivityBotom.class

     @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        Fragment fragment = null;
        switch (item.getItemId()) {
            case R.id.nav_home:
                fragment = new FragmentMarker();
                break;
            case R.id.nav_bookmark:
                fragment = new FragmentBookmark();
                break;
            case R.id.nav_blog:
                fragment = new FragmentMap();
                break;
        }
        getSupportFragmentManager().beginTransaction().replace(R.id.frame_container, fragment).commit();
        return true;

    }

And this is my FragmentMap.class

public class FragmentMap extends Fragment  {

      @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_map, container, false);
        mMapView = getArguments().getParcelable(EXTRA_MARKER_LIST);
        mMapView =  rootView.findViewById(R.id.mapView);
        mMapView.onCreate(savedInstanceState);
        mMapView.onResume(); 
        try {
            MapsInitializer.initialize(getActivity().getApplicationContext());
        } catch (Exception e) {
            e.printStackTrace();
        }

        mMapView.getMapAsync(new OnMapReadyCallback() {
            @RequiresApi(api = Build.VERSION_CODES.M)
            @Override
            public void onMapReady(GoogleMap mMap) {
                googleMap = mMap;
              ...
              Log.d("debug", "problem"); 
                }

                List<Marker> markerList = getActivity().getIntent().getParcelableArrayListExtra(EXTRA_MARKER_LIST);
                for (int i = 0; i < markerList.size(); i++) {
                    Marker marker = markerList.get(i);
                    Location location = marker.getLocation();
                    clusterManager.setItems(markerList);
                }
            }

        });

And i keep getting this error
java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Parcelable android.os.Bundle.getParcelable(java.lang.String)' on a null object reference

I think in case for map myst be Bundle. But i don`t know how to implement it.
I hope someone will help me.
Thanks

Answers: