Parcelable encountered IOException writing serializable object getactivity()

前端 未结 12 1866
故里飘歌
故里飘歌 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:33

    I am also phase these error and i am little bit change in modelClass which are implemented Serializable interface like:

    At that Model class also implement Parcelable interface with writeToParcel() override method

    Then just got error to "create creator" so CREATOR is write and also create with modelclass contructor with arguments & without arguments..

           @Override
            public void writeToParcel(Parcel dest, int flags) {
                dest.writeString(id);
                dest.writeString(name);
            }
    
            protected ArtistTrackClass(Parcel in) {
                id = in.readString();
                name = in.readString();
            }
    
           public ArtistTrackClass() {
    
            }
    
        public static final Creator CREATOR = new Creator() {
            @Override
            public ArtistTrackClass createFromParcel(Parcel in) {
                return new ArtistTrackClass(in);
            }
    
            @Override
            public ArtistTrackClass[] newArray(int size) {
                return new ArtistTrackClass[size];
            }
        };
    

    Here,

    ArtistTrackClass -> ModelClass

    Constructor with Parcel arguments "read our attributes" and writeToParcel() is "write our attributes"

提交回复
热议问题