AnnBnnCnnD 2012-12-21 03:03 采纳率: 0%
浏览 2411
已采纳

为什么一个序列化的栈能反序列化成一个ArrayList

序列化:

Bundle activityArguments = new Bundle();
Stack<Class<? extends WizardStep>> wizardSteps = new Stack<Class<? extends WizardStep>>();
        wizardSteps.push(CreateAlarmStep5View.class);
        wizardSteps.push(CreateAlarmStep4View.class);
        wizardSteps.push(CreateAlarmStep3View.class);
        wizardSteps.push(CreateAlarmStep2View.class);
        wizardSteps.push(CreateAlarmStep1View.class);

        activityArguments.putSerializable("WizardSteps", wizardSteps);

反序列化:

Stack<Class<? extends WizardStep>> wizardSteps = 
(Stack<Class<? extends WizardStep>>) getIntent().getExtras().getSerializable("WizardSteps");

异常:

12-20 23:19:45.698: E/AndroidRuntime(12145): Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Stack
  • 写回答

1条回答 默认 最新

  • ce_la_vie 2012-12-21 03:40
    关注

    这是一个bug。

    使用通用的container:

    public class SerializableHolder implements Serializable {
    private Serializable content;
    public Serializable get() {
        return content;
    }
    public SerializableHolder(Serializable content) {
        this.content = content;
     }
    }
    

    如果用GSON库, 转换栈为String 并且使用没有序列化的单个字符串包

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog