android– 奇怪的NullPointerException没有提示(在spinner上的arrayadaptor的数据中为null)

android– 奇怪的NullPointerException没有提示(在spinner上的arrayadaptor的数据中为null),第1张

概述例外,没有超出此范围.通常logcat有更多有用的信息,但在这种情况下,遗憾的是并不多.07-0613:26:26.654:E/AndroidRuntime(726):java.lang.NullPointerException07-0613:26:26.654:E/AndroidRuntime(726):atandroid.widget.ArrayAdapter.createViewFromResource(ArrayAdap

例外,没有超出此范围.通常logcat有更多有用的信息,但在这种情况下,遗憾的是并不多.

07-06 13:26:26.654: E/AndroIDRuntime(726): java.lang.NullPointerException07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.Widget.ArrayAdapter.createVIEwFromresource(ArrayAdapter.java:355)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.Widget.ArrayAdapter.getVIEw(ArrayAdapter.java:323)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.Widget.Absspinner.onMeasure(Absspinner.java:192)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.vIEw.VIEw.measure(VIEw.java:8313)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:3138)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.Widget.linearLayout.measureChildBeforeLayout(linearLayout.java:1017)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.Widget.linearLayout.measureVertical(linearLayout.java:386)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.Widget.linearLayout.onMeasure(linearLayout.java:309)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.vIEw.VIEw.measure(VIEw.java:8313)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.Widget.ScrollVIEw.measureChilDWithmargins(ScrollVIEw.java:1074)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.Widget.FrameLayout.onMeasure(FrameLayout.java:250)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.Widget.ScrollVIEw.onMeasure(ScrollVIEw.java:296)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.vIEw.VIEw.measure(VIEw.java:8313)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:3138)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.Widget.FrameLayout.onMeasure(FrameLayout.java:250)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.vIEw.VIEw.measure(VIEw.java:8313)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.Widget.linearLayout.measureVertical(linearLayout.java:531)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.Widget.linearLayout.onMeasure(linearLayout.java:309)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.vIEw.VIEw.measure(VIEw.java:8313)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:3138)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.Widget.FrameLayout.onMeasure(FrameLayout.java:250)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.vIEw.VIEw.measure(VIEw.java:8313)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.vIEw.VIEwRoot.performTraversals(VIEwRoot.java:839)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.vIEw.VIEwRoot.handleMessage(VIEwRoot.java:1859)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.os.Handler.dispatchMessage(Handler.java:99)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.os.Looper.loop(Looper.java:130)07-06 13:26:26.654: E/AndroIDRuntime(726):  at androID.app.ActivityThread.main(ActivityThread.java:3683)07-06 13:26:26.654: E/AndroIDRuntime(726):  at java.lang.reflect.Method.invokeNative(Native Method)07-06 13:26:26.654: E/AndroIDRuntime(726):  at java.lang.reflect.Method.invoke(Method.java:507)07-06 13:26:26.654: E/AndroIDRuntime(726):  at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)07-06 13:26:26.654: E/AndroIDRuntime(726):  at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:597)07-06 13:26:26.654: E/AndroIDRuntime(726):  at dalvik.system.NativeStart.main(Native Method)

我的布局xml的开头是(我怀疑在xml的前半部分有些愚蠢错过了)journey.xml

<?xml version="1.0" enCoding="utf-8"?><ScrollVIEw xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent" ><linearLayout    androID:layout_wIDth="fill_parent"    androID:layout_height="wrap_content"    androID:orIEntation="vertical" >    <linearLayout        androID:layout_wIDth="fill_parent"        androID:layout_height="wrap_content"        androID:baselineAligned="false"        androID:orIEntation="horizontal"        androID:weightSum="2" >        <linearLayout            androID:layout_wIDth="wrap_content"            androID:layout_height="fill_parent"            androID:layout_weight="1"            androID:gravity="center"            androID:orIEntation="vertical" >            //Skipped some code I think wont help deBUG this            <Spinner                androID:ID="@+ID/startInMinutes"                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                androID:layout_weight="1" />

第一个活动称为此活动.以下活动的前几行.

@OverrIDepublic voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.journey);    // Some more code    // Adapter related code for ListVIEw    vehicleListVIEw = (Spinner) findVIEwByID(R.ID.vehicleList);    vehicleListVIEw.setAdapter(new ArrayAdapter<String>(this,            androID.R.layout.simple_spinner_item, vehicleList));    vehicleListVIEw.setonItemSelectedListener(this);    vehicleListVIEw.setSelection(0);

编辑:根本原因是,vehicleList数组具有空值.

解决方法:

出现NullPointerException很可能是因为您在ArrayAdapter的构造函数中为您的一个Spinner传递的数组/ List中有空值.

默认情况下,如果ArrayAdapter的数据类型不是CharSequence类型,ArrayAdapter将在数据项上调用方法toString,并使用它来设置行的TextVIEw上的文本.

打印数据数组的值(vehicleList和Globals.TIME_WINDOW),并确保它们中没有空值.

总结

以上是内存溢出为你收集整理的android – 奇怪的NullPointerException没有提示(在spinner上的arrayadaptor的数据中为null)全部内容,希望文章能够帮你解决android – 奇怪的NullPointerException没有提示(在spinner上的arrayadaptor的数据中为null)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1105925.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存