저는 보통 parcelable에는 문제가 없지만 이번에는 NPE를 얻었습니다 ... 고칠 수 없습니다. 제발 친절하게 도와주세요.조각에서 다른 활동으로 소멸 가능한 클래스를 전달합니다.
파편 클래스를 다른 활동으로 전달하려고 시도 할 때 NPE가 발생했습니다. 필자가 활동에서 다른 활동으로, 또는 활동에서 파편으로 파셀 블 클래스를 전달하면 잘 작동한다. 내가 그것을 디버깅 할 때
이것은 child
(parcelable 클래스) 널 내 조각 코드가 없습니다 : 내 목표 onCreate
활동이 여기에
if(v == imgChild)
{
Intent i = new Intent(getActivity(), DetailChildActivity.class);
i.putExtra("child", child);
startActivity(i);
Log.d("menu", "children");
}
:
Bundle data = getIntent().getExtras();
if(data != null)
{
child = data.getParcelable("child"); //NPE here
txtName.setText(child.getName());
}
이 이상하다. 데이터는 null는 아니지만 필 수 가능은 항상 null입니다.
이
내 parcelable입니다 (Child
) 클래스 :
public final Parcelable.Creator<Child> CREATOR = new Parcelable.Creator<Child>() {
public Child createFromParcel(Parcel in) {
return new Child(in);
}
public Child[] newArray(int size) {
return new Child[size];
}
};
private Child(Parcel in) {
id = in.readInt();
user_id = in.readInt();
name = in.readString();
gender = in.readString();
born_date = in.readString();
born_hour = in.readString();
hospital = in.readString();
result = in.readString();
}
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
dest.writeInt(id);
dest.writeInt(user_id);
dest.writeString(name);
dest.writeString(gender);
dest.writeString(born_date);
dest.writeString(born_hour);
dest.writeString(hospital);
dest.writeString(result);
}
이것은 log cat
이 말한 :
예상 타입 com.blabla.child의 수신기 만 가지고 널
시간 내 줘서 고마워.
전체 추적을 다시 게시하고 개체를 읽고 쓰는 코드를 게시 할 수 있습니까? 고마워요 – Fred
@Fred 미안 해요. "전체 추적"이란 무슨 뜻이야? 내 읽기 및 쓸 수있는 코드를 게시 할 것입니다 감사합니다 –
@ Fred done ..... –