so I am getting this in logcat:
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.resources.student_list
For me this was resolved by making the variable withing the class transient.
Code before:
public class UserLocation implements Serializable {
public Location lastKnownLocation;
public UserLocation() {}
}
code after
public class UserLocation implements Serializable {
public transient Location lastKnownLocation;
public UserLocation() {}
}
I faced Same issue, the issues was there are some inner classes with the static keyword.After removing the static keyword it started working and also the inner class should implements to Serializable
class A implements Serializable{
class static B{
}
}
class A implements Serializable{
class B implements Serializable{
}
}
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<ArtistTrackClass> CREATOR = new Creator<ArtistTrackClass>() {
@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"
The exception occurred due to the fact that any of the inner classes or other referenced classes didn't implement the serializable implementation. So make sure that all the referenced classes must implement the serializable implementation.
In my case I had to implement MainActivity
as Serializable
too. Cause I needed to start a service from my MainActivity
:
public class MainActivity extends AppCompatActivity implements Serializable {
...
musicCover = new MusicCover(); // A Serializable Object
...
sIntent = new Intent(MainActivity.this, MusicPlayerService.class);
sIntent.setAction(MusicPlayerService.ACTION_INITIALIZE_COVER);
sIntent.putExtra(MusicPlayerService.EXTRA_COVER, musicCover);
startService(sIntent);
}
if you POJO contains any other model inside that should also implements Serializable