即时通讯使用我的应用程序的底部导航,但每次我用我的 Map 按下片段的按钮,它崩溃 . 我不知道从哪里开始寻找解决方案,因为没有错误 . 我已经拥有我的清单上的所有权限,我的gradle已更新 . 它可能是我的xml,但我尝试了一些组合,仍然没有工作
这是我的fragment_map.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:name="com.example.kristopher.isalon.MainMenu.MapFragment"
android:layout_width="match_parent"
android:layout_height="399dp" />
</LinearLayout>
这是我的MapFragment.java
public class MapFragment extends Fragment implements OnMapReadyCallback {
GoogleMap mGoogleMap;
MapView mMapView;
View mView;
private static final int MY_REQUEST_INT = 177;
private static final String TAG = "MapFragment";
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.fragment_map, container, false);
mMapView = (MapView) mView.findViewById(R.id.map);
if (mMapView != null) {
mMapView.onCreate(null);
mMapView.onResume();
mMapView.getMapAsync(this);
}
return mView;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mGoogleMap = googleMap;
/* check location's permission.*/
if (ContextCompat.checkSelfPermission(getActivity(),
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
//code for permission not granted.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION}, MY_REQUEST_INT);
}
return;
} else {
//code for permission granted.
mGoogleMap.setMyLocationEnabled(true);
mGoogleMap.getUiSettings().setZoomControlsEnabled(true);
}
}
}