NotSerializableException:android.graphics.drawable.BitmapDrawable

时间:2017-06-07 23:41:49

标签: android serialization

我收到以下错误,我知道这意味着某些类必须实现Serializable但问题是我创建的所有类都实现了Serializable。

Process: com.example.awarrior.gallery, PID: 2554
                                                                            java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.example.awarrior.gallery.Item)
                                                                                at android.os.Parcel.writeSerializable(Parcel.java:1526)
                                                                                at android.os.Parcel.writeValue(Parcel.java:1474)
                                                                                at android.os.Parcel.writeArrayMapInternal(Parcel.java:723)
                                                                                at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1408)
                                                                                at android.os.Bundle.writeToParcel(Bundle.java:1133)
                                                                                at android.os.Parcel.writeBundle(Parcel.java:763)
                                                                                at android.content.Intent.writeToParcel(Intent.java:8655)
                                                                                at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:3052)
                                                                                at android.app.Instrumentation.execStartActivity(Instrumentation.java:1518)
                                                                                at android.app.ContextImpl.startActivity(ContextImpl.java:819)
                                                                                at android.app.ContextImpl.startActivity(ContextImpl.java:796)
                                                                                at android.content.ContextWrapper.startActivity(ContextWrapper.java:356)
                                                                                at com.example.awarrior.gallery.ItemAdapter$1.onClick(ItemAdapter.java:57)
                                                                                at android.view.View.performClick(View.java:5610)
                                                                                at android.view.View$PerformClick.run(View.java:22265)
                                                                                at android.os.Handler.handleCallback(Handler.java:751)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                at android.os.Looper.loop(Looper.java:154)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:6077)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
                                                                             Caused by: java.io.NotSerializableException: android.graphics.drawable.BitmapDrawable
                                                                                at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1224)
                                                                                at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1584)
                                                                                at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1549)
                                                                                at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1472)
                                                                                at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1218)
                                                                                at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
                                                                                at android.os.Parcel.writeSerializable(Parcel.java:1521)
                                                                                at android.os.Parcel.writeValue(Parcel.java:1474) 
                                                                                at android.os.Parcel.writeArrayMapInternal(Parcel.java:723) 
                                                                                at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1408) 
                                                                                at android.os.Bundle.writeToParcel(Bundle.java:1133) 
                                                                                at android.os.Parcel.writeBundle(Parcel.java:763) 
                                                                                at android.content.Intent.writeToParcel(Intent.java:8655) 
                                                                                at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:3052) 
                                                                                at android.app.Instrumentation.execStartActivity(Instrumentation.java:1518) 
                                                                                at android.app.ContextImpl.startActivity(ContextImpl.java:819) 
                                                                                at android.app.ContextImpl.startActivity(ContextImpl.java:796) 
                                                                                at android.content.ContextWrapper.startActivity(ContextWrapper.java:356) 
                                                                                at com.example.awarrior.gallery.ItemAdapter$1.onClick(ItemAdapter.java:57) 
                                                                                at android.view.View.performClick(View.java:5610) 
                                                                                at android.view.View$PerformClick.run(View.java:22265) 
                                                                                at android.os.Handler.handleCallback(Handler.java:751) 
                                                                                at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                                at android.os.Looper.loop(Looper.java:154) 
                                                                                at android.app.ActivityThread.main(ActivityThread.java:6077) 
                                                                                at java.lang.reflect.Method.invoke(Native Method)

这是导致错误的代码。

holder.ivImg.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {

                Intent intent = new Intent(context, Detail.class);
                intent.putExtra("item", item);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
            }
        });

1 个答案:

答案 0 :(得分:0)

问题在于您无法序列化位图,因此您可能会对其网址进行序列化,但我不确定如果图像位于drawble文件夹中该怎么办。