单击图库/相机按钮后应用程序崩溃:
java.lang.RuntimeException: Could not copy bitmap to parcel blob.
at android.graphics.Bitmap.nativeWriteToParcel(Native Method)
at android.graphics.Bitmap.writeToParcel(Bitmap.java:2157)
at android.os.Parcel.writeParcelable(Parcel.java:2538)
at android.os.Parcel.writeValue(Parcel.java:2439)
at android.os.Parcel.writeValue(Parcel.java:2316)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:1265)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1802)
at android.os.Bundle.writeToParcel(Bundle.java:1362)
at android.os.Parcel.writeBundle(Parcel.java:1334)
at android.os.Parcel.writeValue(Parcel.java:2433)
at android.os.Parcel.writeValue(Parcel.java:2323)
at android.os.Parcel.writeSparseArray(Parcel.java:1422)
at android.os.Parcel.writeValue(Parcel.java:2463)
at android.os.Parcel.writeValue(Parcel.java:2316)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:1265)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1802)
at android.os.Bundle.writeToParcel(Bundle.java:1362)
at android.os.Parcel.writeBundle(Parcel.java:1334)
at android.os.Parcel.writeValue(Parcel.java:2433)
at android.os.Parcel.writeValue(Parcel.java:2323)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:1265)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1802)
at android.os.Bundle.writeToParcel(Bundle.java:1362)
at android.os.Parcel.writeBundle(Parcel.java:1334)
at android.os.Parcel.writeValue(Parcel.java:2433)
at android.os.Parcel.writeValue(Parcel.java:2323)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:1265)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1802)
at android.os.Bundle.writeToParcel(Bundle.java:1362)
at android.os.Parcel.writeBundle(Parcel.java:1334)
at android.os.Parcel.writeValue(Parcel.java:2433)
at android.os.Parcel.writeValue(Parcel.java:2323)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:1265)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1802)
at android.os.Bundle.writeToParcel(Bundle.java:1362)
at android.os.Parcel.writeTypedObject(Parcel.java:2157)
at android.app.IActivityClientController$Stub$Proxy.activityStopped(IActivityClientController.java:1257)
at android.app.ActivityClient.activityStopped(ActivityClient.java:99)
at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:143)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:210)
at android.os.Looper.loop(Looper.java:299)
at android.app.ActivityThread.main(ActivityThread.java:8247)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:559)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:954)
我的应用程序基本上获取用户输入(字符串/整数值和多个图像 Uri)并构造一个 Record 实例,其中该实例有 8 个参数,每个参数都是不同的类类型,具有多个属性以及唯一的图像 Uri 数组。 用户输入分为3个阶段,每个阶段发生在不同的Fragment中
if (result.getResultCode() == Activity.RESULT_OK) {
Intent data = result.getData();
if (data != null && data.getExtras() != null) {
Bitmap imageBitmap = (Bitmap) data.getExtras().get("data");
if (imageBitmap != null) {
Uri capturedImageUri = getImageUri(requireContext(), imageBitmap);
handleGalleryOrCameraResult(capturedImageUri, requestCode);
} else {
// Handle when the imageBitmap is null
}
}
}
}
private void handleGalleryOrCameraResult(Uri selectedImageUri,int requestCode) {
// Use the appropriate list based on the current scenario
List<Uri> imageList;
TextView imageCounter;
RecyclerView recyclerView;
// Determine the scenario based on your logic
// For example, you can use a flag to identify whether it's for container, lock, or item
switch (requestCode) {
case 7: // Container
imageList = DamageGoodImageUris;
imageCounter = DamageGoodImageCounter;
recyclerView = DamageGoodRecyclerView;
break;
case 8: // Lock
imageList = HeatImageUris;
imageCounter = HeatImageCounter;
recyclerView = HeatRecyclerView;
break;
default:
return;
}
// Add the selected image URI to the respective model's image list
if (selectedImageUri != null) {
imageList.add(selectedImageUri);
}
// Update the RecyclerView with the new image list
setupRecyclerView(recyclerView, imageList, imageCounter);
}
// Helper method to get Uri from Bitmap
private Uri getImageUri(Context context, Bitmap bitmap) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, "Title", null);
return Uri.parse(path);
}
Viewmodel 不起作用