从SherlockFragment启动ACTION_VIEW活动会导致NullPointerException

时间:2013-05-20 05:40:47

标签: android android-intent android-activity actionbarsherlock

我正在使用sherlockFragment 当我按下该片段上的按钮调用以使用Intent启动调用活动时,它导致错误但Web仍然加载。当我关闭通话活动时,错误再次出现 我已经尝试更换最新的android.support.v4.jar,如this,但错误仍然相同 我试过这种方式开始调用活动:

public class PlaceDetailsFragment extends SherlockFragment {
        //blabla
       public void browseWebPage(final String url){
            getSherlockActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(websiteUrl)));
        }
} 

就这样

public class PlaceDetailsFragment extends SherlockFragment {
        //blabla
    public void browseWebPage(final String url){
         Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(websiteUrl));
         startActivity(intent);
    }
}

但仍然有同样的错误 Logcat

05-20 11:37:28.971: E/AndroidRuntime(1819): FATAL EXCEPTION: main
05-20 11:37:28.971: E/AndroidRuntime(1819): java.lang.NullPointerException
05-20 11:37:28.971: E/AndroidRuntime(1819):     at android.support.v4.app.FragmentManagerImpl.saveFragmentBasicState(FragmentManager.java:1576)
05-20 11:37:28.971: E/AndroidRuntime(1819):     at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1617)
05-20 11:37:28.971: E/AndroidRuntime(1819):     at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:481)
05-20 11:37:28.971: E/AndroidRuntime(1819):     at com.actionbarsherlock.app.SherlockFragmentActivity.onSaveInstanceState(SherlockFragmentActivity.java:127)
05-20 11:37:28.971: E/AndroidRuntime(1819):     at android.app.Activity.performSaveInstanceState(Activity.java:1137)
05-20 11:37:28.971: E/AndroidRuntime(1819):     at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1215)
05-20 11:37:28.971: E/AndroidRuntime(1819):     at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:2951)
05-20 11:37:28.971: E/AndroidRuntime(1819):     at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3010)
05-20 11:37:28.971: E/AndroidRuntime(1819):     at android.app.ActivityThread.access$900(ActivityThread.java:130)
05-20 11:37:28.971: E/AndroidRuntime(1819):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1222)
05-20 11:37:28.971: E/AndroidRuntime(1819):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-20 11:37:28.971: E/AndroidRuntime(1819):     at android.os.Looper.loop(Looper.java:137)
05-20 11:37:28.971: E/AndroidRuntime(1819):     at android.app.ActivityThread.main(ActivityThread.java:4745)
05-20 11:37:28.971: E/AndroidRuntime(1819):     at java.lang.reflect.Method.invokeNative(Native Method)
05-20 11:37:28.971: E/AndroidRuntime(1819):     at java.lang.reflect.Method.invoke(Method.java:511)
05-20 11:37:28.971: E/AndroidRuntime(1819):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-20 11:37:28.971: E/AndroidRuntime(1819):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-20 11:37:28.971: E/AndroidRuntime(1819):     at dalvik.system.NativeStart.main(Native Method)

问题出现在ACTION_VIEW和ACTION_CALL上 任何帮助我的解决方案?

1 个答案:

答案 0 :(得分:1)

我找到了解决这个问题的方法。它是通过将sherlockFragment与ViewIndicator或其他东西一起使用而引起的 解决问题,只需将所有片段的menthod覆盖到:

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    setUserVisibleHint(true);
}
找到解决方案here