【问题标题】:android : Why occur "NotSerializableException" even if implements "Serialization"?android:即使实现了“序列化”,为什么还会出现“NotSerializableException”?
【发布时间】:2014-04-15 08:17:23
【问题描述】:

在我的代码下面:

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

    public class Response implements Serializable{
        public String mValue1;
    }

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

所以,我的主要代码是:

 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
 }  

我不知道如何解决这个问题...有人帮帮我!!! T.T

【问题讨论】:

  • 它抛出 java.io.NotSerializableException: ...
  • 关于你未来编码的旁注,因为 Response 实现了 Serializable 并且 ResponseEx 扩展了 Response,ResponseEx 也将隐式地实现 Serializable。现在的代码没有任何问题,但认为以后获得更清晰的代码可能会有所帮助:)
  • 发布堆栈跟踪。它告诉你哪个类是不可序列化的。
  • 我知道...但是堆栈跟踪只是在“startService(intent)”上抛出 NotSerializableException ..
  • @Jul 这不是堆栈跟踪。这是一个例外,甚至不是一个完整的例外。异常消息告诉你类。再试一次。除非您提供适当的信息,否则您将一事无成。

标签: java android serialization notserializableexception


【解决方案1】:

似乎通用 T-Object 有一个不可序列化的引用。

别忘了:T 的所有成员及其成员都必须实现 Serializable

【讨论】:

  • 绝对没有引用任何其他类?
猜你喜欢
  • 2018-03-18
  • 2013-02-06
  • 1970-01-01
  • 2023-03-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-02
  • 1970-01-01
相关资源
最近更新 更多