From 46f3d5ee2258a58e25fa98574dc818442a3800c6 Mon Sep 17 00:00:00 2001 From: Andrei Lazar Date: Fri, 21 Jun 2019 12:22:20 +0000 Subject: [PATCH] Bug 1557661 java.lang.NullPointerException: at org.mozilla.gecko.home.TabMenuStripLayout.onPageSelected(TabMenuStripLayout.java) r=VladBaicu Fixed an issue where we were trying to set some attributes on a null object due to the fact that the view had not finished rendering. Differential Revision: https://phabricator.services.mozilla.com/D35515 --HG-- extra : moz-landing-system : lando --- .../mozilla/gecko/home/TabMenuStripLayout.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mobile/android/base/java/org/mozilla/gecko/home/TabMenuStripLayout.java b/mobile/android/base/java/org/mozilla/gecko/home/TabMenuStripLayout.java index eee6f1afe2f8..118c61e720eb 100644 --- a/mobile/android/base/java/org/mozilla/gecko/home/TabMenuStripLayout.java +++ b/mobile/android/base/java/org/mozilla/gecko/home/TabMenuStripLayout.java @@ -123,20 +123,20 @@ class TabMenuStripLayout extends ThemedLinearLayout } void onPageSelected(final int position) { - if (selectedView != null) { - selectedView.setTextColor(inactiveTextColor); - } - - selectedView = (TextView) getChildAt(position); - selectedView.setTextColor(activeTextColor); - // Callback to measure and draw the strip after the view is visible. - ViewTreeObserver vto = selectedView.getViewTreeObserver(); + ViewTreeObserver vto = getViewTreeObserver(); if (vto.isAlive()) { vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { - selectedView.getViewTreeObserver().removeGlobalOnLayoutListener(this); + // let's ensure that we are calling this only once + vto.removeOnGlobalLayoutListener(this); + if (selectedView != null) { + selectedView.setTextColor(inactiveTextColor); + } + + selectedView = (TextView) getChildAt(position); + selectedView.setTextColor(activeTextColor); if (strip != null) { boolean isLayoutRtl = ViewCompat.getLayoutDirection(selectedView) == ViewCompat.LAYOUT_DIRECTION_RTL;