Parcelable encountered IOException writing serializable object getactivity()

前端 未结 12 1807
故里飘歌
故里飘歌 2020-11-29 22:15

so I am getting this in logcat:

java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.resources.student_list         


        
相关标签:
12条回答
  • 2020-11-29 22:16

    Need to change all arraylist to Serializable wif in bean class :

    public static class PremiumListBean  implements Serializable {
        private List<AddOnValueBean> AddOnValue;
    
        public List<AddOnValueBean> getAddOnValue() {
            return AddOnValue;
         }
    
        public void setAddOnValue(List<AddOnValueBean> AddOnValue) {
            this.AddOnValue = AddOnValue;
        }
    
    
        public static class AddOnValueBean  implements Serializable{
    
            @SerializedName("Premium")
            private String Premium;
    
            public String getPremium() {
                return Premium;
            }
    
            public void setPremium(String Premium) {
                this.Premium = Premium;
            }
        }
     }
    
    0 讨论(0)
  • 2020-11-29 22:19

    The problem occurs when your custom class has for property some other class e.g. "Bitmap". What I made is to change the property field from "private Bitmap photo" to "private transient Bitmap photo". However the image is empty after I getIntent() in the receiver activity. Because of this I passed the custom class to the intent and also I've created a byte array from the image and pass it separatly to the intent:

    selectedItem is my custom object and getPlacePhoto is his method to get image. I've already set it before and now I just get it first than convert it and pass it separatly:

     Bitmap image = selectedItem.getPlacePhoto();
     image.compress(Bitmap.CompressFormat.PNG, 100, stream);
     byte[] byteArray = stream.toByteArray();
     Intent intent = new Intent(YourPresentActivity.this, 
     TheReceiverActivity.class);
     intent.putExtra("selectedItem", selectedItem);                 
     intent.putExtra("image", byteArray);
     startActivity(intent);            
    

    `

    Then in the receiver activity I get my object and the image as byte array, decode the image and set it to my object as photo property.

     Intent intent = getIntent();
     selectedItem = (ListItem) intent.getSerializableExtra("selectedItem");
     byte[] byteArray = getIntent().getByteArrayExtra("image");
     Bitmap image = BitmapFactory.decodeByteArray(byteArray, 0, 
     byteArray.length);
     selectedItem.setPhoto(image);
    
    0 讨论(0)
  • 2020-11-29 22:21

    Your OneThread Class also should implement Serializable. All the sub classes and inner sub classes must implements Serializable.

    this is worked for me...

    0 讨论(0)
  • 2020-11-29 22:21

    the Grade class must also implement Serializable

    public class Grade implements Serializable {
    .....your content....
    }
    
    0 讨论(0)
  • 2020-11-29 22:22
    Caused by: java.io.NotSerializableException: com.resources.student_list.DSLL$DNode
    

    Your DSLL class appears to have a DNode static inner class, and DNode is not Serializable.

    0 讨论(0)
  • 2020-11-29 22:23

    If you can't make DNode serializable a good solution would be to add "transient" to the variable.

    Example:

    public static transient DNode dNode = null;
    

    This will ignore the variable when using Intent.putExtra(...).

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