44、android.os.Parcelable[] cannot be cast to… Error
一、背景
在使用Intant传值时,传递一个实现Parcelable 对象(包含一个列表)时,报出下面的错误:
Caused by: java.lang.ClassCastException: android.os.Parcelable[] cannot be cast to com.taoche.check.business.videoreport.config.VideoReportBaseUIConfig$ExceptionItem[]
at com.taoche.check.business.videoreport.config.VideoReportBaseUIConfig$CheckItem.<init>(VideoReportBaseUIConfig.kt:337)
at com.taoche.check.business.videoreport.config.VideoReportBaseUIConfig$CheckItem$Companion$CREATOR$1.createFromParcel(VideoReportBaseUIConfig.kt:359)
at com.taoche.check.business.videoreport.config.VideoReportBaseUIConfig$CheckItem$Companion$CREATOR$1.createFromParcel(VideoReportBaseUIConfig.kt:358)
at android.os.Parcel.readParcelable(Parcel.java:2471)
at android.os.Parcel.readValue(Parcel.java:2365)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2732)
at android.os.BaseBundle.unparcel(BaseBundle.java:271)
at android.os.Bundle.getParcelable(Bundle.java:864)
at android.content.Intent.getParcelableExtra(Intent.java:6281)
at com.taoche.check.business.condition.NewExceptionActivity.onCreate(NewExceptionActivity.kt:44)
二、解决方法
source.createTypedArray(ExceptionItem.CREATOR) as Array<ExceptionItem>,
//source.readParcelableArray(ExceptionItem::class.java.classLoader) as Array<ExceptionItem>,
writeTypedArray(exceptionItems, flags);
//writeParcelableArray(exceptionItems, 0)