Note that there are some explanatory texts on larger screens.

plurals
  1. PONotSerializableException while saving fragment state
    primarykey
    data
    text
    <p>I'm occasionally seeing exceptions that I do not really understand. Here's what I do: I have an interface</p> <pre><code>public interface IResultProcessor&lt;T&gt; extends Serializable { void processResult(T result); } </code></pre> <p>, instances of which I use in this class:</p> <pre><code>public class ConfirmationDialogFragment extends DialogFragment { public static void executeAfterConfirmation(FragmentActivity activity, IResultProcessor&lt;Void&gt; runnable, String title, String message, int icon, String positiveButtonText, String negativeButtonText) { ConfirmationDialogFragment fragment = new ConfirmationDialogFragment(); Bundle args = new Bundle(); args.putSerializable(ARG_RUNNABLE, runnable); fragment.setArguments(args); fragment.show(activity.getSupportFragmentManager(), "dialog"); } } </code></pre> <p>In the <code>onCreateDialog()</code> method, I receive the <code>IProcessResult</code> instance and execute it if the user has confirmed.</p> <p>I then use all this in an activity as follows:</p> <pre><code>@SuppressWarnings("serial") IResultProcessor&lt;Void&gt; processor = new IResultProcessor&lt;Void&gt;() { @Override public void processResult(Void result) { new AsyncTask&lt;Void, Void, String&gt;() { @Override protected String doInBackground(Void... params) { DBFacade.INSTANCE.saveSession(session); return "My msg..."; } @Override protected void onPostExecute(String result) { Toast.makeText(MyActivity.this, result, Toast.LENGTH_LONG).show(); } }.execute((Void) null); } }; ConfirmationDialogFragment.executeAfterConfirmation(this, processor, "Save session?", "dialog text", R.drawable.ic_dialog_info, "Save", "Don't save"); </code></pre> <p>The <code>session</code> object saved in the <code>AsyncTask</code> does not implement <code>Serializable</code> (but <code>Parcelable</code> because of other reasons) and is a field of MyActivity.</p> <p>And here's the exception I'm seeing:</p> <pre><code>java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = MyActivity$3) at android.os.Parcel.writeSerializable(Parcel.java:1279) at android.os.Parcel.writeValue(Parcel.java:1233) at android.os.Parcel.writeMapInternal(Parcel.java:591) at android.os.Bundle.writeToParcel(Bundle.java:1619) at android.os.Parcel.writeBundle(Parcel.java:605) at android.support.v4.app.FragmentState.writeToParcel(Fragment.java:132) at android.os.Parcel.writeTypedArray(Parcel.java:1102) at android.support.v4.app.FragmentManagerState.writeToParcel(FragmentManager.java:357) at android.os.Parcel.writeParcelable(Parcel.java:1254) at android.os.Parcel.writeValue(Parcel.java:1173) at android.os.Parcel.writeMapInternal(Parcel.java:591) at android.os.Bundle.writeToParcel(Bundle.java:1619) at android.os.Parcel.writeBundle(Parcel.java:605) at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2078) at android.app.ActivityThread$StopInfo.run(ActivityThread.java:2874) at android.os.Handler.handleCallback(Handler.java:615) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4745) 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:786) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method) Caused by: java.io.NotSerializableException: MyActivity at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1364) at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481) at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:979) at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:368) at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1074) at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404) at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481) at android.os.Parcel.writeSerializable(Parcel.java:1274) ... 23 more java.io.NotSerializableException: MyActivity at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1364) at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481) at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:979) at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:368) at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1074) at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404) at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481) at android.os.Parcel.writeSerializable(Parcel.java:1274) at android.os.Parcel.writeValue(Parcel.java:1233) at android.os.Parcel.writeMapInternal(Parcel.java:591) at android.os.Bundle.writeToParcel(Bundle.java:1619) at android.os.Parcel.writeBundle(Parcel.java:605) at android.support.v4.app.FragmentState.writeToParcel(Fragment.java:132) at android.os.Parcel.writeTypedArray(Parcel.java:1102) at android.support.v4.app.FragmentManagerState.writeToParcel(FragmentManager.java:357) at android.os.Parcel.writeParcelable(Parcel.java:1254) at android.os.Parcel.writeValue(Parcel.java:1173) at android.os.Parcel.writeMapInternal(Parcel.java:591) at android.os.Bundle.writeToParcel(Bundle.java:1619) at android.os.Parcel.writeBundle(Parcel.java:605) at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2078) at android.app.ActivityThread$StopInfo.run(ActivityThread.java:2874) at android.os.Handler.handleCallback(Handler.java:615) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4745) 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:786) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>Any idea what's going on here?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload