Strange NullPointerException仅适用于Nexus设备

时间:2014-01-22 15:18:45

标签: java android nullpointerexception

我在PlayStore上的一个应用程序上收到一些奇怪的NullPointerException报告。奇怪的是,这个问题似乎只出现在谷歌Nexus设备上(我有来自Nexus 5(锤头),Nexus 4(mako),Nexus 7(罗非鱼)的报告)。

这里是错误日志:

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)

这是我的活动布局:

<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>

如果没有错误发生,它应该是这样的: screenshot

我知道,很难在这里给出我那些可怜信息的确切答案。也许几乎不可能。但也许有人有类似的问题。或者只是猜测可能导致此问题的原因也可能有所帮助。我的猜测是它可能与TableLayout有关。但我真的不确定。它有什么问题吗?是否有更优雅的方式来创建我的布局?

非常感谢!

0 个答案:

没有答案