diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 8657768ee4c3167d64a19ec3bdd07dc49c242518..1218a5abddc07bb7d7543351bccc51a94ef5e61d 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -186,7 +186,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
 
     public void onSizeChanged() {
         final int width = mInputMethodService.getWindow().getWindow().getDecorView().getWidth();
-        if (width == 0)
+        if (width == 0 || mCurrentId == null)
             return;
         mKeyboardWidth = width;
         // Set keyboard with new width.