gpt4 book ai didi

java - 没有这样的方法错误: No virtual method getMapAsync

转载 作者:行者123 更新时间:2023-12-01 09:00:17 26 4
gpt4 key购买 nike

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

java.lang.NoSuchMethodError: No virtual method getMapAsync(Lcom/google/android/gms/maps/OnMapReadyCallback;)V in class Lcom/google/android/gms/maps/MapFragment; or its super classes (declaration of 'com.google.android.gms.maps.MapFragment' appears in /data/data/com.packagename.appname/files/instant-run/dex/slice-google-play-services_013f7ca48f60d837bd691f2b8fafce962adefa56-classes.dex)

Here's the method itself:

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监视器指向该行以及以下行:

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

fragment 在布局内正确声明。另外,在下面,我重写了 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'
}

最佳答案

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

关于java - 没有这样的方法错误: No virtual method getMapAsync,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41730360/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com