Fix NPE with the unit test

Change-Id: I0836f8b7191287bcff65cdc8a8ce0ff7484e9f65
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
index 76eac1a..00bf348 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
@@ -140,7 +140,7 @@
         // The threshold is "key width" x 1.25
         mSpacebarLanguageSwitchThreshold = (getMostCommonKeyWidth() * 5) / 4;
 
-        if (mSpaceKey != null) {
+        if (mSpaceKey != null && mSpacePreviewIcon != null) {
             final int slidingIconWidth = Math.max(mSpaceKey.mWidth,
                     (int)(getMinWidth() * SPACEBAR_POPUP_MIN_RATIO));
             final int spaceKeyheight = mSpacePreviewIcon.getIntrinsicHeight();