0

我的项目中有以下异常:

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 stackoverflow 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;
    }
4

1 回答 1

0

我认为你应该这样做:

@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;
}
于 2012-12-20T07:03:19.583 回答