What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 133 Stack Exchange communities.

I can not post the following question; it's my first one, and I have no idea what I'm doing wrong. I briefly checked related meta questions, but that didn't help.

     

I'm occasionally seeing exceptions that I do not really understand. Here's what I do: I have an interface

public interface IResultProcessor<T> extends Serializable {

    void processResult(T result);

}

, instances of which I use in this class:

public class ConfirmationDialogFragment extends DialogFragment {

    public static void executeAfterConfirmation(FragmentActivity activity, IResultProcessor<Void> 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");
    }

}

In the onCreateDialog() method, I receive the IProcessResult instance and execute it if the user has confirmed.

I then use all this in an activity as follows:

@SuppressWarnings("serial") 
IResultProcessor<Void> processor = new IResultProcessor<Void>() {

    @Override
    public void processResult(Void result) {
        new AsyncTask<Void, Void, String>() {

            @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");

The session object saved in the AsyncTask does not implement Serializable (but Parcelable because of other reasons) and is a field of MyActivity.

And here's the exception I'm seeing:

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)

Any idea what's going on here?

share|improve this question

closed as too localized by Robert Harvey Oct 31 '12 at 17:07

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

2  
Most likely the exception block at the end is interpreted to be code. Try formatting that as a code block and see if it goes through. –  Bart Oct 31 '12 at 11:12
    
Thanks for the quick help (and for deleting the other, wrong answer :-) What do you mean by "code block"? The exception is already surrounded by <code></code>... –  csoltenborn Oct 31 '12 at 11:15
4  
@hims056 That was a good edit, but: since the error is related to formatting, it might be better to let the question be in the form the OP tried to post it on Stack Overflow. –  Yannis Oct 31 '12 at 11:15
    
@YannisRizos That's fine. Should I rollback it? –  hims056 Oct 31 '12 at 11:18
2  
Ah, I see @hims056 edited the sources of your question, which put me off. Still try formatting it as code using the codesample button in the editor. Not by manually wrapping it in code tags. –  Bart Oct 31 '12 at 11:19
1  
@hims056 Nah, don't bother, people can check the revision history now that we mentioned this isn't the original form of the question. And the root cause of the error is most probably what you fixed, so OP can learn from your edit. –  Yannis Oct 31 '12 at 11:19
    
Thanks, that helped - I thought that I did this with the <code> tags. –  csoltenborn Oct 31 '12 at 11:22
    
@csoltenborn Don't add Thanks in advance.. in the question. –  hims056 Oct 31 '12 at 11:32
    
@hims056 thanks for your advice on stackoverflow best practices - I saw your edit (and was in fact a bit surprised :-) ). Please allow one more question: Do I have to close this question (the meta one) or accept one of the comments as solution or anything? –  csoltenborn Oct 31 '12 at 11:44
    
@csoltenborn What action helped you? (e.g. by removing <code> tag or adding > Blockquote before error or anything else?) –  hims056 Oct 31 '12 at 11:47
    
@hims056 the "don't use code tags, use codesample button instead" one –  csoltenborn Oct 31 '12 at 11:49
    
@csoltenborn Have a look at this post. And feel free to add your own answer. So that in future, other users can also get help from it. –  hims056 Oct 31 '12 at 11:54

Browse other questions tagged .