I have the following GridView and it crashes at times giving me a NullPointer exception in the Adroid GridView.java source code.
It seems that this only happens on Android 2.3.7 - Gingerbread API 10.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_gridFragment"
>
<include
layout="@layout/toolbar_new"/>
<include
layout="@layout/heading_bar"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<GridView
android:id="@+id/main_grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="100dp"
android:numColumns="auto_fit"
android:verticalSpacing="0dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
>
</GridView>
<!-- the Z index is determined by ordering, this is displayed over the Gridview -->
<!-- android:id="@+id/menu" -->
<include
layout="@layout/menu"/>
</FrameLayout>
</LinearLayout>
The Stack trace is here:
FATAL EXCEPTION: main
java.lang.NullPointerException
at android.widget.GridView.fillUp(GridView.java:311)
at android.widget.GridView.fillGap(GridView.java:199)
at android.widget.AbsListView.trackMotionScroll(AbsListView.java:3422)
at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:2920)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3703)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
It seems that mReferenceView is null at line 311. //mReferenceView will change with each call to makeRow()