如何了解Kotlin崩溃日志?

时间:2019-06-27 09:14:06

标签: android kotlin crash-log

缩小后我有一个崩溃日志:

kotlin.KotlinNullPointerException
at com.package_name.SelectRaduisFragment.access$centerLocation(Unknown Source:97)
                                                      access$drawCircle
                                                      access$getErrorMessage
                                                      access$getErrorMessage
                                                      access$getRadiusPosition
                                                      access$getSeekBarPosition
                                                      access$getServices
                                                      access$getServices
                                                      access$setBackgroundTint
                                                      access$setCityId$p
                                                      access$setLatitude$p
                                                      access$setLocationListener$p
                                                      access$setLocationProvider$p
                                                      access$setRadiusChangedJob$p
                                                      access$showParametersFragment
                                                      access$showStationsCount
                                                      access$showUserLocation
                                                      addCircle
                                                      getCircleZoomValue
                                                      getCity
                                                      getErrorMessage
                                                      getErrorMessage
                                                      getServices
                                                      isLocationChanged
                                                      onActivityResult
                                                      onCreateView
                                                      onMapReady
                                                      onRequestPermissionsResult
                                                      setBackgroundTint
                                                      setClickListeners
                                                      showParametersFragment
                                                      showStationsCount
                                                      showUserLocation
at com.package_name.SelectRaduisFragment.access$getCityId$p(Unknown Source:19)
                                                      access$hideProgress
                                                      access$moveMapToLocation
                                                      access$selectRadius
                                                      access$setLongitude$p
                                                      access$setRegionId$p
                                                      access$setSeekBarPosition
                                                      access$showErrorDialog
                                                      drawCircle
                                                      getSeekBarPosition
                                                      showErrorDialog
at com.package_name.SelectRaduisFragment.access$centerLocation(Unknown Source:16)
                                                      access$drawCircle
                                                      access$getErrorMessage
                                                      access$getErrorMessage
                                                      access$getRadiusPosition
                                                      access$getSeekBarPosition
                                                      access$getServices
                                                      access$getServices
                                                      access$setBackgroundTint
... and so on

如何了解NPE发生在哪里?从哪里开始?从列表的顶部还是底部?据我了解,该错误发生在centerLocation中,但不能有错误。

private var latitude: Double = DEFAULT_LATITUDE
private var longitude: Double = DEFAULT_LONGITUDE
private val radiusValues: Array<Int> = arrayOf(5, 10, 25, 50, 100, 200, 0)
private var locationManager: LocationManager? = null
private var locationListener: LocationListener? = null


override fun onCreateView(...) {
    clickListener = View.OnClickListener {
        when (it.id) {
            R.id.center_location -> centerLocation()
            R.id.continue_button -> showParametersFragment(regionId, cityId, latitude, ...)
}

private fun centerLocation() {
    moveMapToLocation(latitude, longitude)
    drawCircle(latitude, longitude)
    if (locationManager?.isProviderEnabled(LocationManager.GPS_PROVIDER) == true ||
        locationManager?.isProviderEnabled(LocationManager.NETWORK_PROVIDER) == true) {
        initLocationListener()
    } else {
        showLocationSettingsDialog()
    }
}

private fun drawCircle(latitude: Double, longitude: Double) {
    if (radiusValues[currentRadiusIndex] == 0) {
        removeCircle()
        moveMapToLocation(latitude, longitude)
    } else {
        addCircle(latitude, longitude)
    }
}

private fun initLocationListener() {
    locationListener = object : LocationListener {
        override fun onLocationChanged(location: Location) {
            removeLocationUpdates()
            locationListener = null

            showUserLocation(location)
        }

        override fun onStatusChanged(provider: String, status: Int, extras: Bundle) {
        }

        @SuppressLint("MissingPermission")
        override fun onProviderEnabled(provider: String) {
            if (isResumed) {
                if (isLocationPermissionGranted()) {
                    locationManager?.getLastKnownLocation(provider)?.let {
                        showUserLocation(it)
                    }
                }
            } else {
                locationProvider = provider
            }
        }

        override fun onProviderDisabled(provider: String) {
        }
    }
    locationManager =
        context?.getSystemService(Context.LOCATION_SERVICE) as? LocationManager
    setLocationUpdates()
}

1 个答案:

答案 0 :(得分:0)

这是不可能的。参见Kotlin code stack trace shows Java line numbershttps://discuss.kotlinlang.org/t/stacktrace-points-to-line-after-end-of-file/4129

我将Kotlin类转换为字节码,将字节码反编译为Java类,这花费了1个小时和3 Gb的内存(〜900行代码)。我试图反编译apk文件,但没有显示所需的类(它们被Proguard缩小了)。

更新

该主题中的错误仅发生在Android 9上。我怀疑我应该升级Google Maps库。