首页 > 解决方案 > Kotlin NullPointerException 问题

问题描述

我正在使用 Google Map 制作应用程序,但我遇到了权限问题。有人可以帮助我吗?虽然 Android 10 没有问题,但 Android 9 有这个问题。这些 106-115 行的代码

if (ContextCompat.checkSelfPermission(this,android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED){
            requestPermissions(arrayOf(android.Manifest.permission.ACCESS_FINE_LOCATION),1)

        }else{
            locationManager!!.requestLocationUpdates(LocationManager.GPS_PROVIDER,2,2f,locationListener)
            mMap.clear()
            var lastLocation = locationManager!!.getLastKnownLocation(LocationManager.GPS_PROVIDER)
            var lastUserLocation = LatLng(lastLocation!!.latitude,lastLocation!!.longitude)
            mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(lastUserLocation,17f))
        }

在此处输入图像描述

标签: androidkotlin

解决方案


推荐阅读