这个代码我已经写过好几次了.但从今天早上开始,我看到这个问题发生了.这是显示 map 布局的基本代码.向我展示这个错误.我还正确输入了API密钥.Screen Shot of Emulator我搜索了其他StackOverflow帖子,但没有任何效果.

package com.example.maptest

import android.support.v7.app.AppCompatActivity
import android.os.Bundle

import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.SupportMapFragment
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.MarkerOptions

class MapsActivity : AppCompatActivity(), OnMapReadyCallback {

    private lateinit var mMap: GoogleMap

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_maps)
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        val mapFragment = supportFragmentManager
            .findFragmentById(R.id.map) as SupportMapFragment
        mapFragment.getMapAsync(this)
    }

    /**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */
    override fun onMapReady(googleMap: GoogleMap) {
        mMap = googleMap

        // Add a marker in Sydney and move the camera
        val sydney = LatLng(-34.0, 151.0)
        mMap.addMarker(MarkerOptions().position(sydney).title("Marker in Sydney"))
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney))
    }
}

Xml file:-

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      xmlns:map="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:id="@+id/map"
      tools:context=".MapsActivity"
      android:name="com.google.android.gms.maps.SupportMapFragment"/>

App level gradle:-

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.maptest"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.google.android.gms:play-services-maps:16.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

项目级成绩:-

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.3.21'
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

推荐答案

I solved this problem.

通过更改应用程序级别的Gradle依赖关系

from this

implementation 'com.google.android.gms:play-services-maps:16.1.0'

对这个

implementation 'com.google.android.gms:play-services-maps:16.0.0'

Update:

Now i can use this latest gradle dependency. It works fine for me.

implementation 'com.google.android.gms:play-services-maps:16.1.0'

Kotlin相关问答推荐

了解Kotlin函数

在KMP中使用koin将来自Android的上下文注入到SQLDelight Driver中

Kotlin多平台(KMP)保存到文件不能在iOS上保存

Kotlin Coroutine()是如何工作的?S阻止了.

Kotlin接口方法默认值&;可传递依赖项

kotlin 模式匹配如何像 scala 一样工作

Kotlin 中的密封和内部有什么区别?

Kotlin 插件之间的区别

奇怪的 cotlin check Not Null 参数错误

如何从 kotlin 函数中 Select 正确的枚举值

如何在 Kotlin 中使用具有继承的泛型

在 Kotlin 中通过反射获取 Enum 值

使用 Kotlin 创建新目录,Mkdir() 不起作用

如何在 Spring WebFlux 的响应正文中流式传输二进制数据

取消信号上的kotlin流量采集

kotlin-bom 库是做什么的?

如何捕获传递给模拟函数的参数并返回它?

Dagger +Kotlin 不注入

Android:Exoplayer - ExtractorMediaSource 已弃用

Kotlin,什么时候按map授权?