Parcelable encountered IOException writing serializable object getactivity()
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
.
Java android ava.lang.RuntimeException: Parcelable encountered IOException writing serializable object
Try replacing Serializable implementation with Parcelable in Vals & RawBean classes
Replace getSerializableExtra with getParcelableExtra in *onActivityResult**
Vals.java
public class Vals implements Serializable, Parcelable {
public ArrayList<RowBean> data;
public Vals(ArrayList<RowBean> data) {
this.data = data;
}
protected Vals(Parcel in) {
if (in.readByte() == 0x01) {
data = new ArrayList<RowBean>();
in.readList(data, RowBean.class.getClassLoader());
} else {
data = null;
}
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
if (data == null) {
dest.writeByte((byte) (0x00));
} else {
dest.writeByte((byte) (0x01));
dest.writeList(data);
}
}
@SuppressWarnings("unused")
public static final Parcelable.Creator<Vals> CREATOR = new Parcelable.Creator<Vals>() {
@Override
public Vals createFromParcel(Parcel in) {
return new Vals(in);
}
@Override
public Vals[] newArray(int size) {
return new Vals[size];
}
};
}
RawBean.java
public class RowBean implements Serializable, Parcelable {
public String title;
public boolean selected;
public RowBean(){
}
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
public RowBean(boolean selected, String title) {
this.selected = selected;
this.title = title;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
protected RowBean(Parcel in) {
title = in.readString();
selected = in.readByte() != 0x00;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(title);
dest.writeByte((byte) (selected ? 0x01 : 0x00));
}
@SuppressWarnings("unused")
public static final Parcelable.Creator<RowBean> CREATOR = new Parcelable.Creator<RowBean>() {
@Override
public RowBean createFromParcel(Parcel in) {
return new RowBean(in);
}
@Override
public RowBean[] newArray(int size) {
return new RowBean[size];
}
};
}
parcelable encountered ioexception writing serializable object.........?
Ok i implemented part of it for you. You have to add all the other properties of your SongDetails class:
MainActivity.java:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SongDetails Songinfo1 = new SongDetails();
Songinfo1.setSong("song1");
SongDetails Songinfo2 = new SongDetails();
Songinfo2.setSong("song2");
ArrayList<SongDetails> list = new ArrayList<SongDetails>();
list.add(Songinfo1);
list.add(Songinfo2);
Intent intent = new Intent(this, SecondActivity.class);
intent.putParcelableArrayListExtra("Data1", list);
intent.putExtra("Data2", 1);
startActivity(intent);
}
In the activity in which you are retrieving the songs, use this:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_asdf);
ArrayList<SongDetails> songs = getIntent().getParcelableArrayListExtra("Data1");
for(SongDetails songDetails : songs) {
Log.i("", songDetails.getSong());
}
}
Your SongDetails class should look like this:
SongDetails:
public class SongDetails implements Parcelable {
Bitmap icon;
String song;
String Artist;
String Album;
String Path;
int icLauncher;
public SongDetails() {
}
public SongDetails(Parcel in) {
String[] data = new String[1];
in.readStringArray(data);
this.song = data[0];
}
public String getSong() {
return song;
}
public void setSong(String song) {
this.song = song;
}
public String getArtist() {
return Artist;
}
public void setArtist(String Artist) {
this.Artist = Artist;
}
public Bitmap getIcon() {
return icon;
}
public void setIcon(Bitmap bitmap) {
this.icon = bitmap;
}
public String getPath2() {
return Path;
}
public void setPath2(String Path) {
this.Path = Path;
}
public String getAlbum() {
return Album;
}
public void setAlbum(String Album) {
this.Album = Album;
}
public void setIcon(int icLauncher) {
this.icLauncher = icLauncher;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeStringArray(new String[] { this.song });
}
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public SongDetails createFromParcel(Parcel in) {
return new SongDetails(in);
}
public SongDetails[] newArray(int size) {
return new SongDetails[size];
}
};
}
Parcelable encountered IOException writing serializable object when I don't serialize anything
So I have an answer to the problem. This answers has base on the answers given on this post:
Why is it possible to pass a Drawable trough a Bundle from one Activity to a Fragment?
The answer is simple, as when passing objects as arguments to a Fragment
will not cause it to be Marshled. This means it wouldn't be Serialized/Deserialized unless the Fragment
is destroyed. And in this case he is destroyed when I try to start a new Activity
. I tought Drawable
was serializable cause I wasn't getting any errors while I was inside the Fragment
, little did I know I was dealing with the same object (reference) itself.
Parcelable encountered IOException writing serializable object in Fragment
Your VaccineDetailsModel must implements as Serializable
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.jaapp.treeview.InMemoryTreeStateManager)
The root cause of your problem is
Caused by: java.io.NotSerializableException: com.jaapp.dto.QuestionsDto
which clearly indicates that your class is not serializable.
Make sure your class implements the Serializable marker interface.
Related Topics
When Exactly Are Onsaveinstancestate() and Onrestoreinstancestate() Called
Login Error: There Is an Error in Logging You into This Application. Please Try Again Later
How to Create Converter for My Class in Android Retrofit Library
How to Use Android Emulator for Testing Bluetooth Application
How to Compile a Static Library Using the Android Ndk
Calculate the Size of a List View or How to Tell It to Fully Expand
Multiple Dex Files Define Lorg/Apache/Cordova/Buildhelper
Android: Change Default Home Application
Getting Started with Open Nfc Emulator
Android: How to Change the Actionbar "Home" Icon to Be Something Other Than the App Icon
How to Embed a Custom Font in an Android Application
How to Remove Shared Preference While Application Uninstall in Android
Scaled Bitmap Maintaining Aspect Ratio
How to Programmatically Add a Submenu Item to the New Material Design Android Support Library
How to Combine Bottomappbar + Fab with Bottomnavigationview