无法暂停活动 DroFeedsActivity:java.lang.NullPointerException
Posted
技术标签:
【中文标题】无法暂停活动 DroFeedsActivity:java.lang.NullPointerException【英文标题】:Unable to pause activity DroFeedsActivity: java.lang.NullPointerException无法暂停活动 DroFeedsActivity:java.lang.NullPointerException 【发布时间】:2012-12-20 06:04:47 【问题描述】:我的项目中有以下异常:
12-20 05:51:49.641: E/androidRuntime(426): java.lang.RuntimeException: Unable to pause activity com.dz.dro/com.dz.dro.DroFeedsActivity: java.lang.NullPointerException
12-20 05:51:49.641: E/AndroidRuntime(426): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3162)
12-20 05:51:49.641: E/AndroidRuntime(426): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3119)
12-20 05:51:49.641: E/AndroidRuntime(426): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3102)
12-20 05:51:49.641: E/AndroidRuntime(426): at android.app.ActivityThread.access$2400(ActivityThread.java:119)
12-20 05:51:49.641: E/AndroidRuntime(426): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1870)
12-20 05:51:49.641: E/AndroidRuntime(426): at android.os.Handler.dispatchMessage(Handler.java:99)
12-20 05:51:49.641: E/AndroidRuntime(426): at android.os.Looper.loop(Looper.java:123)
12-20 05:51:49.641: E/AndroidRuntime(426): at android.app.ActivityThread.main(ActivityThread.java:4363)
12-20 05:51:49.641: E/AndroidRuntime(426): at java.lang.reflect.Method.invokeNative(Native Method)
12-20 05:51:49.641: E/AndroidRuntime(426): at java.lang.reflect.Method.invoke(Method.java:521)
12-20 05:51:49.641: E/AndroidRuntime(426): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-20 05:51:49.641: E/AndroidRuntime(426): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-20 05:51:49.641: E/AndroidRuntime(426): at dalvik.system.NativeStart.main(Native Method)
12-20 05:51:49.641: E/AndroidRuntime(426): Caused by: java.lang.NullPointerException
12-20 05:51:49.641: E/AndroidRuntime(426): at android.support.v4.app.FragmentManagerImpl.saveFragmentBasicState(FragmentManager.java:1576)
12-20 05:51:49.641: E/AndroidRuntime(426): at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1617)
12-20 05:51:49.641: E/AndroidRuntime(426): at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:481)
12-20 05:51:49.641: E/AndroidRuntime(426): at com.actionbarsherlock.app.SherlockFragmentActivity.onSaveInstanceState(SherlockFragmentActivity.java:127)
12-20 05:51:49.641: E/AndroidRuntime(426): at android.app.Activity.performSaveInstanceState(Activity.java:1022)
12-20 05:51:49.641: E/AndroidRuntime(426): at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1180)
12-20 05:51:49.641: E/AndroidRuntime(426): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3144)
12-20 05:51:49.641: E/AndroidRuntime(426): ... 12 more
当我在我的项目中使用带有 carasoul 效果的寻呼机 adpater 的 action bar sherlock 库时。对于每个部分,我定义了单独的片段。在我的应用程序中,一切都很顺利,但是当我单击 sherlock 操作栏中的操作菜单项时,它会抛出上述错误,我尝试了几种解决此问题的方法。
And I gone through several *** links which is similar to my issue, none of the links solves my probs
我使用以下方法将片段添加到 sectionpageradapter 中:
@Override
public Fragment getItem(int position)
Fragment fragment = new Fragment();
switch(position)
case 0 :
fragment = new ListUserFeedFragment("some url");
break;
case 1 :
fragment = new ListAllFeedFragment("some url");
break;
return fragment;
【问题讨论】:
如果有帮助,请查看这两个帖子。 ***.com/questions/9292047/…***.com/questions/8748064/… 【参考方案1】:我认为你应该这样做:
@Override
public Fragment getItem(int position)
ListUserFeedFragment fragment;
switch(position)
case 0 :
fragment = new ListUserFeedFragment("some url");
break;
case 1 :
fragment = new ListAllFeedFragment("some url");
break;
return fragment;
【讨论】:
以上是关于无法暂停活动 DroFeedsActivity:java.lang.NullPointerException的主要内容,如果未能解决你的问题,请参考以下文章
如何在基础活动暂停时暂停rxjava Observable.interval