【问题标题】:NoSuchMethodError: No virtual method getMapAsyncNoSuchMethodError:没有虚拟方法 getMapAsync
【发布时间】:2017-01-18 22:11:18
【问题描述】:

我正在尝试重振我在 2014 年制作的旧 Google 地图应用程序。除了一个问题之外,我没有遇到任何问题:尝试在我上面在同一个类中调用的自定义方法中初始化地图,我得到这个错误:

java.lang.NoSuchMethodError:Lcom/google/android/gms/maps/MapFragment 类中没有虚拟方法 getMapAsync(Lcom/google/android/gms/maps/OnMapReadyCallback;)V;或其超类(“com.google.android.gms.maps.MapFragment”的声明出现在 /data/data/com.packagename.appname/files/instant-run/dex/slice-google-play-services_013f7ca48f60d837bd691f2b8fafce962adefa56-classes .dex)

这是方法本身:

private void initilizeMap()
{
    if (mGoogleMap == null) {
        MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
                == PackageManager.PERMISSION_GRANTED) {
            mGoogleMap.setMyLocationEnabled(true);
        } else {
            Toast.makeText(this, "You have to accept to enjoy all app's services!", Toast.LENGTH_LONG).show();
        }
    }
}

方法 initializeMap() 在其声明上方被调用,Android Monitor 指向该行以及该行:

MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);

片段在布局内正确声明。另外,在下面,我已经覆盖了 onMapReady 方法:

@Override
public void onMapReady(GoogleMap googleMap)
{
    mGoogleMap = googleMap;
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
            == PackageManager.PERMISSION_GRANTED) {
        mGoogleMap.setMyLocationEnabled(true);
    }
}

我不知道是什么导致了这个问题。

编辑(build.gradle 依赖项):

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.android.support:design:25.1.0'
    compile 'com.google.maps.android:android-maps-utils:0.4+'
    testCompile 'junit:junit:4.12'
    compile files('libs/android-google-maps-api13.jar')
    compile 'com.google.android.gms:play-services:8.4.0'
    apply plugin: 'com.google.gms.google-services'
    compile files('libs/google-play-services.jar')
    compile 'com.google.android.gms:play-services-maps:8.4.0'
}

【问题讨论】:

  • 你能分享你的build.gradle吗?
  • 我假设您想查看依赖项?在上面添加它们。

标签: java android google-maps


【解决方案1】:

您在运行时看到的MapFragment 实例没有预期的方法。看起来您是使用较新版本编译的,然后用于运行您的应用程序。

【讨论】:

  • 我需要一个 SupportFragmentMap 代替吗?还是其他类型?
猜你喜欢
  • 1970-01-01
  • 2018-10-28
  • 1970-01-01
  • 2020-10-28
  • 2019-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多