ClassCastException 随机发生以在 onRestoreInstanceState() 中恢复 Vector。一般恢复向量都可以很好地完成,但有时会出现异常。
我认为当活动进入后台并被销毁时会发生这种情况,但我不确定。
有任何想法吗?谢谢你。
Stack<LocationInfo> mLocationInfoVector;
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putSerializable("locationInfos", mLocationInfoVector);
super.onSaveInstanceState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
if (savedInstanceState.getSerializable("locationInfos") != null) {
@SuppressWarnings("unchecked")
mLocationInfoVector= (Stack<LocationInfo>) savedInstanceState.getSerializable("locationInfos");
}
super.onRestoreInstanceState(savedInstanceState);
}
添加:
我忘了附上异常日志。那是
java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Stack