如何解决“无法元帅值”错误

时间:2019-09-24 07:48:07

标签: android gallery marshalling

当我尝试通过单击按钮从Android应用程序打开图库时。它抛出"Unable to marshal value"异常。以下是给我错误的代码。

第一次尝试时,打开图库时没有错误。单击几下后,如果我转到该特定片段并单击“选择图像”图标,则会引发错误。

    if (requestCode == REQUEST_CODE_GALLERY){
        if(grantResults.length>0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){
            Intent intent = new Intent(Intent.ACTION_PICK);
            intent.setType("image/*");
            startActivityForResult(intent, REQUEST_CODE_GALLERY);

        }
        else {
            Toast.makeText(getContext(),"Permission not Enabled", Toast.LENGTH_SHORT).show();
        }
        return;
    }
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

    if(requestCode == REQUEST_CODE_GALLERY && resultCode == RESULT_OK  && data != null){
        Uri uri = data.getData();

        try {
            InputStream inputStream = getActivity().getApplicationContext().getContentResolver().openInputStream(uri);

            bitmap = BitmapFactory.decodeStream(inputStream);
            productImage.setImageBitmap(bitmap);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    super.onActivityResult(requestCode, resultCode, data);
}

我得到的错误:

  

E / Android运行时:致命异常:主要       流程:com.example.smartdisplay,PID:24822       java.lang.RuntimeException:包裹:无法封送值com.example.smartdisplay.DisplayData@bb07760           在android.os.Parcel.writeValue(Parcel.java:1508)           在android.os.Parcel.writeList(Parcel.java:820)           在android.os.Parcel.writeValue(Parcel.java:1455)           在android.os.Parcel.writeArrayMapInternal(Parcel.java:732)           在android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1423)           在android.os.Bundle.writeToParcel(Bundle.java:1133)           在android.os.Parcel.writeBundle(Parcel.java:772)           在androidx.fragment.app.FragmentState.writeToParcel(FragmentState.java:124)           在android.os.Parcel.writeTypedArray(Parcel.java:1338)           在androidx.fragment.app.FragmentManagerState.writeToParcel(FragmentManager.java:639)           在android.os.Parcel.writeParcelable(Parcel.java:1527)           在android.os.Parcel.writeValue(Parcel.java:1433)           在android.os.Parcel.writeArrayMapInternal(Parcel.java:732)           在android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1423)           在android.os.Bundle.writeToParcel(Bundle.java:1133)           在android.os.Parcel.writeBundle(Parcel.java:772)           在android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:3685)           在android.app.ActivityThread $ StopInfo.run(ActivityThread.java:3865)           在android.os.Handler.handleCallback(Handler.java:754)           在android.os.Handler.dispatchMessage(Handler.java:95)           在android.os.Looper.loop(Looper.java:165)           在android.app.ActivityThread.main(ActivityThread.java:6375)           在java.lang.reflect.Method.invoke(本机方法)           在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:912)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)   I / Process:正在发送信号。 PID:24822 SIG:9应用程序终止。

我想念什么?

0 个答案:

没有答案