Reputation: 199
I'm using Android Studio 1.1, and AP1 21 (version required as part of a course). I create a new project using the Google Maps Activity
.
Within the automatically generated code, I get the following error message: Error:(48, 21) error: cannot find symbol method getMap()
, in the setUpMapIfNeeded
method:
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
Any ideas how to fix this problem? Thanks!
Upvotes: 0
Views: 1354
Reputation: 1094
I was using same methods and I got same error. And I fixed it by implementing OnMapReadyCallback.
Firstly implement OnMapReadyCallback:
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
@Override
protected void onCreate(Bundle savedInstanceState) {
......
....
New setUpMapIfNeeded() method:
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
SupportMapFragment mf = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mf.getMapAsync(this);
}
}
And call setUpMap() in overrided onMapReady:
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
setUpMap();
}
There is no change in setUpMap() method or other methods. I hope it helps.
Upvotes: 0