From 71f1f67662a827f39d3bdb0f695587b1007f542b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrique=20L=C3=B3pez=20Ma=C3=B1as?= Date: Fri, 23 Dec 2022 13:22:20 +0100 Subject: [PATCH] fix: fixed NPE on OnMapAndViewReadyListener (#1116) --- .../kotlindemos/OnMapAndViewReadyListener.kt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/OnMapAndViewReadyListener.kt b/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/OnMapAndViewReadyListener.kt index bd6cf07c2..b685d36a7 100644 --- a/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/OnMapAndViewReadyListener.kt +++ b/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/OnMapAndViewReadyListener.kt @@ -53,14 +53,15 @@ class OnMapAndViewReadyListener( private fun registerListeners() { // View layout. - if (mapView?.width != 0 && mapView?.height != 0) { - // View has already completed layout. - isViewReady = true - } else { - // Map has not undergone layout, register a View observer. - mapView.viewTreeObserver.addOnGlobalLayoutListener(this) + mapView?.let { + if (it.width != 0 && it.height != 0) { + // View has already completed layout. + isViewReady = true + } else { + // Map has not undergone layout, register a View observer. + it.viewTreeObserver.addOnGlobalLayoutListener(this) + } } - // GoogleMap. Note if the GoogleMap is already ready it will still fire the callback later. mapFragment.getMapAsync(this) }