我使用的是Android Studio1.1和AP1 21 (作为课程的一部分需要的版本)。我使用Google Maps Activity
创建了一个新项目。
在自动生成的代码中,我在setUpMapIfNeeded
方法中得到以下错误消息:Error:(48, 21) error: cannot find symbol method getMap()
:
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();
}
}
}
有什么办法解决这个问题吗?谢谢!
发布于 2016-11-27 18:02:28
我使用了同样的方法,也得到了同样的错误。我通过实现OnMapReadyCallback修复了这个问题。
首先实现OnMapReadyCallback:
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
@Override
protected void onCreate(Bundle savedInstanceState) {
......
....
新的setUpMapIfNeeded()方法:
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);
}
}
并在重写的onMapReady中调用setUpMap():
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
setUpMap();
}
setUpMap()方法或其他方法没有变化。我希望它能帮上忙。
https://stackoverflow.com/questions/39086431
复制相似问题