1

Below my code:

    public interface Callback<T extends Response> extends Serializable{
        void onSuccess(T response);
        void onFail(String errMsg);
    }

AND

    public class Response implements Serializable{
        public String mValue1;
    }

AND

    public class ResponseEx extends Response implements Serializable{
        public String mValue2;
    }

So, my main code is :

 public class TestActivity extends Activity{

     Callback<ResponseEx> callback = new Callback<ResponseEx>() {
            @Override
            public void onSuccess(ResponseEx response) {
            }

            @Override
            public void onFail(String errMsg) {
            }
        }
    Intent intent = new Intent("ACTION");
    intent.putExtra("KEY", callback); 

    startService(intent);  //onFail
 }  

I have no idea to resolve this problem... somebody help me!!! T.T

JuL
  • 113
  • 1
  • 7
  • It throws java.io.NotSerializableException: ... – JuL Apr 15 '14 at 08:18
  • Side note for your future coding, since Response implements Serializable and ResponseEx extends Response, ResponseEx will also implement Serializable implicitly. There's nothing wrong with the code as it is now, but thought that maybe it would help later to get cleaner code :) – Pphoenix Apr 15 '14 at 08:22
  • Post the stack trace. It *tells* you what class wasn't serializable. – user207421 Apr 15 '14 at 08:24
  • I know...But stack trace just throw NotSerializableException on "startService(intent)".. – JuL Apr 15 '14 at 08:32
  • @Jul That is not a stack trace. That's an exception, and not even a complete one. The exception message tells you the class. Try again. You're not going to get anywhere until you provide proper information. – user207421 Apr 15 '14 at 08:33

1 Answers1

0

It seems like the generic T-Object has a not-serializable reference.

Don't forget: all members and also their members of T have to implement Serializable

Niko
  • 1,054
  • 5
  • 25
  • 52