首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >错误:(48,21)错误:找不到符号方法getMap()

错误:(48,21)错误:找不到符号方法getMap()
EN

Stack Overflow用户
提问于 2016-08-23 02:33:04
回答 1查看 1.3K关注 0票数 0

我使用的是Android Studio1.1和AP1 21 (作为课程的一部分需要的版本)。我使用Google Maps Activity创建了一个新项目。

在自动生成的代码中,我在setUpMapIfNeeded方法中得到以下错误消息:Error:(48, 21) error: cannot find symbol method getMap()

代码语言:javascript
运行
复制
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();
            }
        }
    } 

有什么办法解决这个问题吗?谢谢!

EN

回答 1

Stack Overflow用户

发布于 2016-11-27 18:02:28

我使用了同样的方法,也得到了同样的错误。我通过实现OnMapReadyCallback修复了这个问题。

首先实现OnMapReadyCallback:

代码语言:javascript
运行
复制
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
@Override
protected void onCreate(Bundle savedInstanceState) {
    ......
    ....

新的setUpMapIfNeeded()方法:

代码语言:javascript
运行
复制
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():

代码语言:javascript
运行
复制
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    setUpMap();
}

setUpMap()方法或其他方法没有变化。我希望它能帮上忙。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39086431

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档