使用设备进行测试 – 每当我锁定屏幕(或闲置1分钟后休眠),应用程序崩溃,logcat会在onResume()方法的imageVIEw.setonClickListener上显示NullPointerException.
这是我获得异常的代码的一小部分:
protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.critical_items_List); // instantiate member variables mExtras = getIntent().getExtras(); mItems_P1 = mExtras.getParcelableArrayList(EXTRA_ITEMS_P1); mItems_P2 = mExtras.getParcelableArrayList(EXTRA_ITEMS_P2); mItems_Engine = mExtras.getParcelableArrayList(EXTRA_ITEMS_ENGINE); }protected voID onResume() { super.onResume(); ImageVIEw imageAddToMultiple = (ImageVIEw) findVIEwByID(R.ID.image_add_to_multiple); //This is where the I get the NullPointer imageAddToMultiple.setonClickListener(ListenerAddToMultipleItems); refreshLists(); ListVIEw ListP1 = (ListVIEw) findVIEwByID(R.ID.List_p1); ListVIEw ListP2 = (ListVIEw) findVIEwByID(R.ID.List_p2); ListVIEw ListEngine = (ListVIEw) findVIEwByID(R.ID.List_engine); ListP1.setAdapter(new MyAdapter(mList_P1)); ListP2.setAdapter(new MyAdapter(mList_P2)); ListEngine.setAdapter(new MyAdapter(mList_Engine));}
imageVIEw本身位于relativeLayout:
我不知道为什么我会得到这个NullPointer.
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to resume activity {nmw.nss/nmw.nss.CriticalList}: java.lang.NullPointerException at
androID.app.ActivityThread.performResumeActivity(ActivityThread.java:2820)
at
androID.app.ActivityThread.handleResumeActivity(ActivityThread.java:2859)
at
androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2242)
at androID.app.ActivityThread.access$600(ActivityThread.java:139) at
androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
at androID.os.Handler.dispatchMessage(Handler.java:99) at
androID.os.Looper.loop(Looper.java:154) at
androID.app.ActivityThread.main(ActivityThread.java:4974) at
java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:511) at
com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:551) at
dalvik.system.NativeStart.main(Native Method) Caused by:
java.lang.NullPointerException at
nmw.nss.CriticalList.onResume(CriticalList.java:93)
at
androID.app.Instrumentation.callActivityOnResume(Instrumentation.java:1236)
at androID.app.Activity.performResume(Activity.java:4620) at
androID.app.ActivityThread.performResumeActivity(ActivityThread.java:2804)
… 12 more
谢谢.
编辑:我添加了完整的活动(类型),xml和logcat.
我是否需要覆盖任何Activity方法,可能是onStop或onPause以使其工作?最佳答案终于找到了!
我的应用程序基本上是在横向模式下运行,而在清单中我添加了——-
机器人:screenorIEntation = “风景”.
好吧,这就是问题:在你锁定设备的模式下,findVIEwByID()总是在纵向模式下搜索XML并且在我的情况下,根本没有ImageVIEw.因此NullPointerException.
总结 以上是内存溢出为你收集整理的android – 应用程序在锁定/睡眠屏幕崩溃 – NullPointerException全部内容,希望文章能够帮你解决android – 应用程序在锁定/睡眠屏幕崩溃 – NullPointerException所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)