出现这个异常的原因是因为在调用Parcel类的诸如readList(List outVal, ClassLoader loader)的API时传入了错误的loader,这里容器里面放入的是什么类就需要使用什么loader,例如List<MyClass>,就需要传入MyClass.class.getClassLoader()
另外在自己的类实现Parcelable接口的时候,如果其中使用到了非基础类型MyClass,那么MyClass也是需要实现Parcelable接口的,否则会报出AndroidRuntime error: Parcel: unable to marshal value
参考:http://stackoverflow.com/questions/3818745/androidruntime-error-parcel-unable-to-marshal-value
本文解析了在使用Parcel类API时因传入错误的ClassLoader导致的异常,并提供了正确的解决方案。此外,还介绍了当自定义类实现Parcelable接口时,如何确保所有非基础类型也实现了Parcelable接口,避免运行时错误。
4621

被折叠的 条评论
为什么被折叠?



