Merge "Fix bug 5201420 - Appease the monkeys"
diff --git a/core/java/android/widget/ListView.java b/core/java/android/widget/ListView.java
index 133f435..5a97317 100644
--- a/core/java/android/widget/ListView.java
+++ b/core/java/android/widget/ListView.java
@@ -3384,11 +3384,11 @@
     protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
         super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
 
+        final ListAdapter adapter = mAdapter;
         int closetChildIndex = -1;
-        if (gainFocus && previouslyFocusedRect != null) {
+        if (adapter != null && gainFocus && previouslyFocusedRect != null) {
             previouslyFocusedRect.offset(mScrollX, mScrollY);
 
-            final ListAdapter adapter = mAdapter;
             // Don't cache the result of getChildCount or mFirstPosition here,
             // it could change in layoutChildren.
             if (adapter.getCount() < getChildCount() + mFirstPosition) {