在我的应用中,我使用底部导航视图。在第三个片段中必须是map。而且我不知道该如何发送数据。
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;
}
这是我的 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);
}
}
});
而且我不断收到此错误
java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Parcelable android.os.Bundle.getParcelable(java.lang.String)' on a null object reference
我认为万一map myst是Bundle。但是我不知道如何实现它。 我希望有人能帮助我。 谢谢
答案 0 :(得分:0)
您可以使用参数发送数据
Bundle bundle = new Bundle();
bundle.putSerializable(EXTRA_MARKER_LIST, ________);
fragment = new FragmentMap();
fragment.setArguments(bundle);
这将解决问题