Problem serializing Drawable

前端 未结 2 1650
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-22 18:41

I\'ve got a singe object which has three fields: two strings and a Drawable

public class MyObject implements Serializable {

    private static fina         


        
相关标签:
2条回答
  • 2021-01-22 19:12

    You can't serialize that.

    Simply put, if BitmapDrawable isn't Serializable, then you can't serialize it. Usually things like this aren't serializable because they are holding on to references to things that aren't pure data. Like a context or a handle to a drawing surface.

    0 讨论(0)
  • 2021-01-22 19:19
    java.io.NotSerializableException: android.graphics.drawable.BitmapDrawable
    

    This message seems pretty clear - the specific drawable instance in the photo field is a BitmapDrawable, which wasn't designed to be serialized. Your class cannot be serialized without dealing with the non-serializable field.

    If you can ensure your class will always have a BitmapDrawable or a Bitmap, you can see this code for an example of how to handle a Bitmap field:

    android how to save a bitmap - buggy code

    0 讨论(0)
提交回复
热议问题