在我将 getMap() 更改为 getMapAsync() 并实现 OnMapReadyCallback 后,我收到错误 NullPointerException。
这里是 logcat
引起:java.lang.NullPointerException:尝试在 pym.example.com.fypv2.callme.Callme 的空对象引用上调用虚拟方法“void com.google.android.gms.maps.GoogleMap.setMyLocationEnabled(boolean)” .onCreate(Callme.java:117)`
这里的代码
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
// Enabling MyLocation in Google Map
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation …Run Code Online (Sandbox Code Playgroud)