1

I am getting some strange NullPointerException reports on one of my apps on PlayStore. The weird thing is, that this problem only seems to appear on Google Nexus devices (I've got reports from Nexus 5 (hammerhead), Nexus 4 (mako), Nexus 7 (tilapia)).

Here the error log:

java.lang.NullPointerException
at android.widget.TextView.makeNewLayout(TextView.java:6113)
at android.widget.TextView.onMeasure(TextView.java:6408)
at android.view.View.measure(View.java:16497)
at android.widget.Spinner.setUpChild(Spinner.java:632)
at android.widget.Spinner.makeView(Spinner.java:585)
at android.widget.Spinner.getBaseline(Spinner.java:431)
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1089)
at android.widget.TableRow.onMeasure(TableRow.java:114)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.TableLayout.measureChildBeforeLayout(TableLayout.java:464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.TableLayout.measureVertical(TableLayout.java:476)
at android.widget.TableLayout.onMeasure(TableLayout.java:439)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16497)
at android.widget.ScrollView.onMeasure(ScrollView.java:350)
at android.view.View.measure(View.java:16497)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
at android.view.View.measure(View.java:16497)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1916)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1113)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1295)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)

Here my activity layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ns="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".SettingsActivity" >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:fillViewport="true" >

        <LinearLayout
            style="@style/mainContainer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <LinearLayout
                style="@style/subContainer"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >

                <TextView
                    style="@style/subContainerTitle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/you" >
                </TextView>

                <TableLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" >

                    <TableRow
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" >

                        <EditText
                            android:id="@+id/editHeight"
                            style="@style/input"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:ellipsize="end"
                            android:gravity="right"
                            android:hint="@string/height"
                            android:inputType="numberDecimal"
                            android:singleLine="true" />

                        <Spinner
                            android:id="@+id/spinnerHeightUnits"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical"
                            android:entries="@array/heightUnits" />

                        <EditText
                            android:id="@+id/editWeight"
                            style="@style/input"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="8dp"
                            android:layout_weight="1"
                            android:ellipsize="end"
                            android:gravity="right"
                            android:hint="@string/weight"
                            android:inputType="numberDecimal"
                            android:singleLine="true" />

                        <Spinner
                            android:id="@+id/spinnerWeightUnits"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical"
                            android:entries="@array/weightUnits" />
                    </TableRow>

                    <TableRow
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" >

                        <EditText
                            android:id="@+id/editAge"
                            style="@style/input"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:ellipsize="end"
                            android:gravity="right"
                            android:hint="@string/age"
                            android:inputType="number"
                            android:singleLine="true" />

                        <TextView
                            android:id="@+id/labelYears"
                            style="@style/spinner"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical|right"
                            android:background="@android:color/transparent"
                            android:text="@string/years" />

                        <RelativeLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_marginLeft="8dp"
                            android:layout_span="2"
                            android:layout_weight="1" >

                            <Spinner
                                android:id="@+id/spinnerGender"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_alignParentRight="true"
                                android:layout_centerVertical="true"
                                android:entries="@array/genderLabels"
                                android:gravity="right"
                                android:textAlignment="viewEnd" />
                        </RelativeLayout>
                    </TableRow>
                </TableLayout>
            </LinearLayout>

            <LinearLayout
                android:id="@+id/editPresets"
                style="@style/subContainer"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="6dp"
                android:orientation="vertical"
                android:padding="0dp" >

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal" >

                    <TextView
                        style="@style/subContainerTitle"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:layout_marginLeft="-6dp"
                        android:text="▶"
                        android:textSize="36sp" />

                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:orientation="vertical"
                        android:padding="6dp" >

                        <TextView
                            style="@style/subContainerTitle"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/presets" >
                        </TextView>

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/presetText" >
                        </TextView>
                    </LinearLayout>
                </LinearLayout>
            </LinearLayout>

            <LinearLayout
                style="@style/subContainer"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="6dp"
                android:orientation="vertical" >

                <TextView
                    style="@style/subContainerTitle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/units" >
                </TextView>

                <TableLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:stretchColumns="1" >

                    <TableRow>

                        <TextView android:text="@string/drinkVolume" />

                        <Spinner
                            android:id="@+id/spinnerVolumeUnits"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="3dp"
                            android:entries="@array/volumeUnitLabels" />
                    </TableRow>

                    <TableRow>

                        <TextView android:text="@string/pureAlcohol" />

                        <Spinner
                            android:id="@+id/spinnerAlcoholUnits"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="3dp"
                            android:entries="@array/alcoholUnitLabels" />
                    </TableRow>

                    <TableRow>

                        <TextView android:text="@string/energy" />

                        <Spinner
                            android:id="@+id/spinnerEnergyUnits"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="3dp"
                            android:entries="@array/energyUnitLabels" />
                    </TableRow>
                </TableLayout>
            </LinearLayout>
        </LinearLayout>
    </ScrollView>

    <[...].gui.AdView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

Here is how it is supposed to look like if no error occurs: screenshot

I know, it's difficult to give me an exact answer with those poor information here. Maybe almost impossible. But maybe somebody had some similar problems. Or only a guess what could cause this problem might help as well. My guess would be that it COULD have something to do with the TableLayout. But I am really unsure. Is there anything wrong with it? Are there more elegant ways to create my layout?

Thanks anyway!

flxapps
  • 1,066
  • 1
  • 11
  • 24
  • 5
    perhaps this may help you: http://stackoverflow.com/questions/20176877/weird-nullpointerexception-in-spinner – waqaslam Jan 22 '14 at 15:24
  • Please give your activity code.I guess in activity you are referring to a textview which is null. – Zohra Khan Jan 22 '14 at 15:27
  • If those Nexus 4 and 7 devices are running KitKat, Waqas' comment probably leads to your solution! – MalaKa Jan 22 '14 at 15:31

0 Answers0