티스토리 뷰
Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.
Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.
아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.
Parcelable encountered IOException writing serializable object getactivity()
Parcelable가 Serializable 객체 getactivity()를 작성하는 동안 IOException을 만났습니다
문제 내용
so I am getting this in logcat:
로그캣에서 이런 오류 메시지를 받고 있습니다:
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.resources.student_list.Student)
I know this means that my student class is not serializable, but it is, here is my student class:
저는 이것이 제 학생 클래스가 직렬화 가능하지 않다는 것을 의미한다는 것을 알고 있지만, 여기 제 학생 클래스가 있습니다.
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());
}
}
and this is the code that is using the getIntent() method:
이것은 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);
}
});
please help me figure out whats wrong with this.
이 코드에서 발생하는 문제를 찾아주세요.
here is the whole LogCat:
여기는 전체 LogCat 내용입니다:
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)
높은 점수를 받은 Solution
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
.
당신의 DSLL 클래스는 DNode 정적 내부 클래스를 가지고 있습니다. DNode 클래스는 Serializable이 아닙니다.
가장 최근 달린 Solution
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.
이 예외가 발생한 이유는 내부 클래스 또는 다른 참조된 클래스 중 하나가 직렬화 구현을 하지 않았기 때문입니다. 따라서 참조된 모든 클래스가 직렬화 구현을 해야 합니다.
출처 : https://stackoverflow.com/questions/23142893/parcelable-encountered-ioexception-writing-serializable-object-getactivity
'개발 > 안드로이드' 카테고리의 다른 글
안드로이드에서 "뒤로" 버튼을 눌러도 Activity가 종료되지 않게 하는 방법 (0) | 2023.01.20 |
---|---|
Android에서 화면 회전 방지하기 (0) | 2023.01.20 |
전화 걸기 앱에서 특정 전화번호가 표시되도록 하기 (0) | 2023.01.18 |
ArrayList를 SharedPreferences에 저장하기 (0) | 2023.01.17 |
Android Fragment 에서 뒤로 가기 버튼 처리하기 (0) | 2023.01.16 |