gpt4 book ai didi

android - NullPointerException android.support.v4.app.FragmentManagerImpl.saveFragmentBasicState

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:55:36 26 4
gpt4 key购买 nike

在使用 Share Intent 时,应用程序崩溃并出现以下错误

01-25 12:16:09.270: E/AndroidRuntime(28699): FATAL EXCEPTION: main
01-25 12:16:09.270: E/AndroidRuntime(28699): java.lang.NullPointerException
01-25 12:16:09.270: E/AndroidRuntime(28699): at android.support.v4.app.FragmentManagerImpl.saveFragmentBasicState(FragmentManager.java:1576)
01-25 12:16:09.270: E/AndroidRuntime(28699): at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1617)
01-25 12:16:09.270: E/AndroidRuntime(28699): at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:481)
01-25 12:16:09.270: E/AndroidRuntime(28699): at com.actionbarsherlock.app.SherlockFragmentActivity.onSaveInstanceState(SherlockFragmentActivity.java:127)
01-25 12:16:09.270: E/AndroidRuntime(28699): at android.app.Activity.performSaveInstanceState(Activity.java:1113)
01-25 12:16:09.270: E/AndroidRuntime(28699): at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1188)
01-25 12:16:09.270: E/AndroidRuntime(28699): at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:2805)
01-25 12:16:09.270: E/AndroidRuntime(28699): at android.app.ActivityThread.handleStopActivity(ActivityThread.java:2863)
01-25 12:16:09.270: E/AndroidRuntime(28699): at android.app.ActivityThread.access$900(ActivityThread.java:127)
01-25 12:16:09.270: E/AndroidRuntime(28699): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1173)
01-25 12:16:09.270: E/AndroidRuntime(28699): at android.os.Handler.dispatchMessage(Handler.java:99)
01-25 12:16:09.270: E/AndroidRuntime(28699): at android.os.Looper.loop(Looper.java:137)
01-25 12:16:09.270: E/AndroidRuntime(28699): at android.app.ActivityThread.main(ActivityThread.java:4507)
01-25 12:16:09.270: E/AndroidRuntime(28699): at java.lang.reflect.Method.invokeNative(Native Method)
01-25 12:16:09.270: E/AndroidRuntime(28699): at java.lang.reflect.Method.invoke(Method.java:511)
01-25 12:16:09.270: E/AndroidRuntime(28699): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
01-25 12:16:09.270: E/AndroidRuntime(28699): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
01-25 12:16:09.270: E/AndroidRuntime(28699): at dalvik.system.NativeStart.main(Native Method)

PlacesActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_share:
// Google Analytics Tracking
GATracker.sendEvent("ui_action", "button_press", "share",
click_value);

shareIt();
break;
default:
break;
}
return true;
}


private void shareIt() {
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");

String shareText = name + "\n" + distance + " kms - " + days + " days"
+ "\n" + todo + "\n\n"
+ "Check out Nomad for Android http://goo.gl/i1mH9";

sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"Check out this!!");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareText);
startActivity(Intent.createChooser(sharingIntent, "Share via"));
}

最佳答案

它是某种错误(或可能不是)。但请尝试以下操作:对于所有 fragment ,如下覆盖 onSaveInstanceState

@Override 
public void onSaveInstanceState(Bundle outState)
{
//first saving my state, so the bundle wont be empty.
outState.putString("WORKAROUND_FOR_BUG_19917_KEY", "WORKAROUND_FOR_BUG_19917_VALUE");
super.onSaveInstanceState(outState);
}

这个link有更多的见识

关于android - NullPointerException android.support.v4.app.FragmentManagerImpl.saveFragmentBasicState,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14516804/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com