Parceable 错误:在偏移量 1112 处解组未知类型代码 7274595
Posted
技术标签:
【中文标题】Parceable 错误:在偏移量 1112 处解组未知类型代码 7274595【英文标题】:Parceable error : Unmarshalling unknown type code 7274595 at offset 1112 【发布时间】:2020-05-06 17:42:53 【问题描述】:我从两个片段进入活动,并通过意图传递额外内容,第一个意图是数据
Intent intent = new Intent(getContext(), AllAlbumImgActivity.class);
photoGrapherSavedPhoto.albumName=getResources().getString(R.string.photos);
intent.putExtra(SELECTED_IMG_ID, photoGrapherSavedPhoto.id);
intent.putExtra(LIST_NAME, getActivity().getResources().getString(R.string.photos));
intent.putExtra(LIST_TYPE, CURRENT_PHOTOGRAPHER_PHOTOS_LIST);
intent.putExtra(CURRENT_PAGE, nextPageUrl);
intent.putParcelableArrayListExtra(ALL_ALBUM_IMAGES, (ArrayList<? extends Parcelable>) photoGrapherPhotoList);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivityForResult(intent, ALBUM_LIST_REQUEST_CODE);
效果很好
第二个意图
Intent intent = new Intent(getContext(), AllAlbumImgActivity.class);
photoGrapherSavedPhoto.albumName="Saved";
intent.putExtra(SELECTED_IMG_ID, photoGrapherSavedPhoto.id);
intent.putExtra(LIST_NAME, getActivity().getResources().getString(R.string.saved));
intent.putExtra(LIST_TYPE, CURRENT_PHOTOGRAPHER_SAVED_LIST);
intent.putExtra(CURRENT_PAGE, nextPageUrl);
intent.putParcelableArrayListExtra(ALL_ALBUM_IMAGES, (ArrayList<? extends Parcelable>) photoGrapherSavedPhotoList);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivityForResult(intent, ALBUM_LIST_REQUEST_CODE);
但它不适用于第二个意图数据
这是我接收数据的方式
if (intent.getSerializableExtra(LIST_TYPE) != null)
photosListType = (Constants.PhotosListType) intent.getSerializableExtra(LIST_TYPE);
if (intent.getStringExtra(LIST_NAME) != null)
topBarTitle.setText(intent.getStringExtra(LIST_NAME));
if (photosListType == CURRENT_PHOTOGRAPHER_PHOTOS_LIST || photosListType == CURRENT_PHOTOGRAPHER_SAVED_LIST)
nextPageUrl = intent.getStringExtra(CURRENT_PAGE);
if (intent.getParcelableArrayListExtra(ALL_ALBUM_IMAGES) != null)
this.albumImgList = intent.getParcelableArrayListExtra(ALL_ALBUM_IMAGES);
int selectedPosition = intent.getIntExtra(SELECTED_IMG_ID, 0);
for (int i = 0; i < albumImgList.size(); i++)
if (albumImgList.get(i).id == selectedPosition)
// Objects.requireNonNull(allAlbumImgRv.getLayoutManager()).smoothScrollToPosition(allAlbumImgRv, null, i);
scrolledPosition = i;
break;
但是当我通过第二个意图时,它会显示此错误
E/androidRuntime: FATAL EXCEPTION: main
Process: com.example.softmills.phlog, PID: 14899
java.lang.RuntimeException: Unable to start activity ComponentInfocom.example.softmills.phlog/com.example.softmills.phlog.ui.album.view.AllAlbumImgActivity: java.lang.RuntimeException: Parcel android.os.Parcel@b21b847: Unmarshalling unknown type code 7274595 at offset 1100
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.RuntimeException: Parcel android.os.Parcel@b21b847: Unmarshalling unknown type code 7274595 at offset 1100
at android.os.Parcel.readValue(Parcel.java:2747)
at android.os.Parcel.readListInternal(Parcel.java:3098)
at android.os.Parcel.readArrayList(Parcel.java:2319)
at android.os.Parcel.readValue(Parcel.java:2689)
at android.os.Parcel.readArrayMapInternal(Parcel.java:3037)
at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:288)
at android.os.BaseBundle.unparcel(BaseBundle.java:232)
at android.os.BaseBundle.getSerializable(BaseBundle.java:1227)
at android.os.Bundle.getSerializable(Bundle.java:1034)
at android.content.Intent.getSerializableExtra(Intent.java:7516)
at com.example.softmills.phlog.ui.album.view.AllAlbumImgActivity.initView(AllAlbumImgActivity.java:97)
at com.example.softmills.phlog.ui.album.view.AllAlbumImgActivity.onCreate(AllAlbumImgActivity.java:85)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
我将所有专辑作为 parceable 传递,并且在两个意图中它具有相同的对象
但是一项工作和一项产生与 parcelable 相关的奇怪错误!
【问题讨论】:
【参考方案1】:你可以试试这个:
#Parcel
-keepclassmembers class * implements android.os.Parcelable
static ** CREATOR;
将此添加到proguard,它可以帮助你。
【讨论】:
以上是关于Parceable 错误:在偏移量 1112 处解组未知类型代码 7274595的主要内容,如果未能解决你的问题,请参考以下文章