Spinner setSelection在某些设备中返回null异常

时间:2015-08-07 13:57:52

标签: android nullpointerexception spinner

我的spinner的setSelection(int position)仅在某些设备中返回null point exception。我找到了一个我必须使用setSelection(int position, boolean animate)的解决方案。但是,该解决方案意味着onItemSelected调用,因此在我的情况下,我无法使用setSelection(int position, boolean animate)。该问题还有其他解决方案吗?为什么只在某些设备上发生?

以下是我的代码示例:

holder.spinnerService.setSelection(_serviceSelected.getAmount() - 1);

我调试了代码,位置_serviceSelected.getAmount() - 1存在于spinner中,因此这不是问题。

错误追踪:

08-07 10:56:46.844    9980-9986/? E/jdwp﹕ Failed sending reply to debugger: Broken pipe
08-07 10:56:47.019    9980-9980/? E/ERROR﹕ java.lang.NullPointerException
        at android.widget.TextView.makeNewLayout(TextView.java:6327)
        at android.widget.TextView.onMeasure(TextView.java:6607)
        at android.view.View.measure(View.java:16581)
        at android.widget.Spinner.setUpChild(Spinner.java:654)
        at android.widget.Spinner.makeView(Spinner.java:617)
        at android.widget.Spinner.getBaseline(Spinner.java:433)
        at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1091)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:592)
        at android.view.View.measure(View.java:16581)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5140)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1406)
        at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1054)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:592)
        at android.view.View.measure(View.java:16581)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5140)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1406)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:697)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:590)
        at android.view.View.measure(View.java:16581)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5140)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1406)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:697)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:590)
        at android.view.View.measure(View.java:16581)
        at android.widget.ListView.setupChild(ListView.java:1870)
        at android.widget.ListView.makeAndAddView(ListView.java:1793)
        at android.widget.ListView.fillDown(ListView.java:691)
        at android.widget.ListView.fillFromTop(ListView.java:752)
        at android.widget.ListView.layoutChildren(ListView.java:1630)
        at android.widget.AbsListView.onLayout(AbsListView.java:2130)
        at android.view.View.layout(View.java:14898)
        at android.view.ViewGroup.layout(ViewGroup.java:4646)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1673)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1527)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1436)
        at android.view.View.layout(View.java:14898)
        at android.view.ViewGroup.layout(ViewGroup.java:4646)
        at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1626)
        at android.view.View.layout(View.java:14898)
        at android.view.ViewGroup.layout(ViewGroup.java:4646)
        at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
        at android.view.View.layout(View.java:14898)
        at android.view.ViewGroup.layout(ViewGroup.java:4646)
        at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:907)
        at android.view.View.layout(View.java:14898)
        at android.view.ViewGroup.layout(ViewGroup.java:4646)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1673)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1527)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1436)
        at android.view.View.layout(View.java:14898)
        at android.view.ViewGroup.layout(ViewGroup.java:4646)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
        at android.view.View.layout(View.java:14898)
        at android.view.ViewGroup.layout(ViewGroup.java:4646)
        at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:374)
        at android.view.View.layout(View.java:14898)
        at android.view.ViewGroup.layout(ViewGroup.java:4646)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
        at android.view.View.layout(View.java:14898)
        at android.view.ViewGroup.layout(ViewGroup.java:4646)
        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2032)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1789)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1044)
        at android.view.ViewRootImpl$TraversalRunnable

0 个答案:

没有答案