如果使用的是Android包,为什么一个序列化堆栈deserialise作为一个ArrayList? [英] When using an android bundle, why does a serialised stack deserialise as an ArrayList?
本文介绍了如果使用的是Android包,为什么一个序列化堆栈deserialise作为一个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);
Deserialisation:
Deserialisation:
Stack<Class<? extends WizardStep>> wizardSteps =
(Stack<Class<? extends WizardStep>>) getIntent().getExtras().getSerializable("WizardSteps");
例外:
12-20 23:19:45.698:E / AndroidRuntime(12145):java.lang.ClassCastException:产生的原因的java.util.ArrayList不能转换为java.util.Stack中
12-20 23:19:45.698: E/AndroidRuntime(12145): Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Stack
推荐答案
其已知的错误。我奇怪,它仍然存在。
Its known bug. I surprise that it still exists.
使用通用容器,如:
public class SerializableHolder implements Serializable {
private Serializable content;
public Serializable get() {
return content;
}
public SerializableHolder(Serializable content) {
this.content = content;
}
}
如果您使用 GSON
库,将您的堆栈为String,并作为捆绑一个String没有顺序使用。它应该工作。
If you use GSON
library, convert your Stack to String and use as single String for Bundle without Serialize. It should work.
这篇关于如果使用的是Android包,为什么一个序列化堆栈deserialise作为一个ArrayList?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文