Skip to content

Commit 71f1f67

Browse files
authored
fix: fixed NPE on OnMapAndViewReadyListener (#1116)
1 parent 8b6d096 commit 71f1f67

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/OnMapAndViewReadyListener.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,15 @@ class OnMapAndViewReadyListener(
5353

5454
private fun registerListeners() {
5555
// View layout.
56-
if (mapView?.width != 0 && mapView?.height != 0) {
57-
// View has already completed layout.
58-
isViewReady = true
59-
} else {
60-
// Map has not undergone layout, register a View observer.
61-
mapView.viewTreeObserver.addOnGlobalLayoutListener(this)
56+
mapView?.let {
57+
if (it.width != 0 && it.height != 0) {
58+
// View has already completed layout.
59+
isViewReady = true
60+
} else {
61+
// Map has not undergone layout, register a View observer.
62+
it.viewTreeObserver.addOnGlobalLayoutListener(this)
63+
}
6264
}
63-
6465
// GoogleMap. Note if the GoogleMap is already ready it will still fire the callback later.
6566
mapFragment.getMapAsync(this)
6667
}

0 commit comments

Comments
 (0)