Parcelable encontró IOException al escribir objeto serializable getactivity()
entonces obtengo esto en logcat:
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.resources.student_list.Student)
Sé que esto significa que mi clase de estudiante no es serializable, pero lo es, aquí está mi clase de estudiante:
import java.io.Serializable;
public class Student implements Comparable<Student>, Serializable{
private static final long serialVersionUID = 1L;
private String firstName, lastName;
private DSLL<Grade> gradeList;
public Student() {
firstName = "";
lastName = "";
gradeList = new DSLL<Grade>();
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public DSLL<Grade> getGradeList() {
return gradeList;
}
public void setGradeList(DSLL<Grade> gradeList) {
this.gradeList = gradeList;
}
public int compareTo(Student arg0) {
return this.lastName.compareTo(arg0.getLastName());
}
}
y este es el código que utiliza el método getIntent():
public void onItemClick(AdapterView<?> parent, View viewClicked, int pos,
long id) {
Student clickedStudent = studentList.get(pos);
int position = pos;
Intent intent = new Intent(getActivity().getApplicationContext(), ShowStudentActivity.class);
Log.e("CINTENT","CREATED!!!");
intent.putExtra("clickedStudent",clickedStudent);
intent.putExtra("newStudentList",newStudentList);
intent.putExtra("position",position);
Log.e("putExtra","Passed");
Log.e("Start activity","passed");
startActivity(intent);
}
});
por favor ayúdenme a descubrir qué hay de malo en esto.
aquí está el LogCat completo:
04-17 16:12:28.890: E/AndroidRuntime(22815): FATAL EXCEPTION: main
04-17 16:12:28.890: E/AndroidRuntime(22815): java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.resources.student_list.Student)
04-17 16:12:28.890: E/AndroidRuntime(22815): at android.os.Parcel.writeSerializable(Parcel.java:1181)
04-17 16:12:28.890: E/AndroidRuntime(22815): at android.os.Parcel.writeValue(Parcel.java:1135)
04-17 16:12:28.890: E/AndroidRuntime(22815): at android.os.Parcel.writeMapInternal(Parcel.java:493)
04-17 16:12:28.890: E/AndroidRuntime(22815): at android.os.Bundle.writeToParcel(Bundle.java:1612)
04-17 16:12:28.890: E/AndroidRuntime(22815): at android.os.Parcel.writeBundle(Parcel.java:507)
04-17 16:12:28.890: E/AndroidRuntime(22815): at android.content.Intent.writeToParcel(Intent.java:6111)
04-17 16:12:28.890: E/AndroidRuntime(22815): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1613)
04-17 16:12:28.890: E/AndroidRuntime(22815): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1422)
04-17 16:12:28.890: E/AndroidRuntime(22815): at android.app.Activity.startActivityForResult(Activity.java:3191)
04-17 16:12:28.890: E/AndroidRuntime(22815): at android.support.v4.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:848)
04-17 16:12:28.890: E/AndroidRuntime(22815): at android.support.v4.app.Fragment.startActivity(Fragment.java:878)
04-17 16:12:28.890: E/AndroidRuntime(22815): at com.example.student_lists.MainActivity$DummySectionFragment$2.onItemClick(MainActivity.java:477)
04-17 16:12:28.890: E/AndroidRuntime(22815): at android.widget.AdapterView.performItemClick(AdapterView.java:292)
04-17 16:12:28.890: E/AndroidRuntime(22815): at android.widget.AbsListView.performItemClick(AbsListView.java:1058)
04-17 16:12:28.890: E/AndroidRuntime(22815): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)
04-17 16:12:28.890: E/AndroidRuntime(22815): at android.widget.AbsListView$1.run(AbsListView.java:3168)
04-17 16:12:28.890: E/AndroidRuntime(22815): at android.os.Handler.handleCallback(Handler.java:605)
04-17 16:12:28.890: E/AndroidRuntime(22815): at android.os.Handler.dispatchMessage(Handler.java:92)
04-17 16:12:28.890: E/AndroidRuntime(22815): at android.os.Looper.loop(Looper.java:137)
04-17 16:12:28.890: E/AndroidRuntime(22815): at android.app.ActivityThread.main(ActivityThread.java:4447)
04-17 16:12:28.890: E/AndroidRuntime(22815): at java.lang.reflect.Method.invokeNative(Native Method)
04-17 16:12:28.890: E/AndroidRuntime(22815): at java.lang.reflect.Method.invoke(Method.java:511)
04-17 16:12:28.890: E/AndroidRuntime(22815): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-17 16:12:28.890: E/AndroidRuntime(22815): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-17 16:12:28.890: E/AndroidRuntime(22815): at dalvik.system.NativeStart.main(Native Method)
04-17 16:12:28.890: E/AndroidRuntime(22815): Caused by: java.io.NotSerializableException: com.resources.student_list.DSLL$DNode
04-17 16:12:28.890: E/AndroidRuntime(22815): at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1364)
04-17 16:12:28.890: E/AndroidRuntime(22815): at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
04-17 16:12:28.890: E/AndroidRuntime(22815): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
04-17 16:12:28.890: E/AndroidRuntime(22815): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
04-17 16:12:28.890: E/AndroidRuntime(22815): at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:979)
04-17 16:12:28.890: E/AndroidRuntime(22815): at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:368)
04-17 16:12:28.890: E/AndroidRuntime(22815): at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1074)
04-17 16:12:28.890: E/AndroidRuntime(22815): at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
04-17 16:12:28.890: E/AndroidRuntime(22815): at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
04-17 16:12:28.890: E/AndroidRuntime(22815): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
04-17 16:12:28.890: E/AndroidRuntime(22815): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
04-17 16:12:28.890: E/AndroidRuntime(22815): at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:979)
04-17 16:12:28.890: E/AndroidRuntime(22815): at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:368)
04-17 16:12:28.890: E/AndroidRuntime(22815): at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1074)
04-17 16:12:28.890: E/AndroidRuntime(22815): at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
04-17 16:12:28.890: E/AndroidRuntime(22815): at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
04-17 16:12:28.890: E/AndroidRuntime(22815): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
04-17 16:12:28.890: E/AndroidRuntime(22815): at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
04-17 16:12:28.890: E/AndroidRuntime(22815): at android.os.Parcel.writeSerializable(Parcel.java:1176)
Caused by: java.io.NotSerializableException: com.resources.student_list.DSLL$DNode
Su DSLL
clase parece tener una DNode
clase interna estática y DNode
no lo es Serializable
.
Su clase OneThread también debería implementar Serializable. Todas las subclases y subclases internas deben implementar Serializable .
esto me funcionó...
si su POJO contiene cualquier otro modelo dentro que también debería implementar Serializable
Si no puede hacer que DNode sea serializable, una buena solución sería agregar "transitorio" a la variable.
Ejemplo:
public static transient DNode dNode = null;
Esto ignorará la variable cuando se use Intent.putExtra(...).