Intent
을 통해 객체를 전달하는 데 문제가 있습니다. 널 포인터 오류가 계속 발생합니다. 여기있다 : 내 ListActivity에서액티비티간에 소화물 항목 전달
다음 DetailsActivity 클래스의에서 onCreate에서
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Intent intent = new Intent(MyListActivity.this, DetailsActivity.class);
intent.putExtra("this_item", my_array.get(position));
startActivity(intent);
}
() :
thisItem = (MyObject) getIntent().getExtras().getParcelable("this_item");
System.err.println(thisItem.getDescription()); //<--Null pointer error!
MyObject
클래스는 Parcelable
을 구현 않습니다. 왜이 객체를 넘길 수 없습니까? 나는 혼란스러워. 어떤 도움을 주셔서 감사합니다.
편집 : 여기에 그 클래스는 다음과 같습니다
public class MyObject implements Comparable<MyObject>, Parcelable {
private Date date;
private MyType my_type;
private String description;
private int flags;
public MyObject(Date date, MyType type, String desc) {
this.date = date;
this.my_type = type;
this.description = desc;
}
public Date getDate() {return date;}
public MyType getMyType() {return my_type;}
public String getDescription() {return description;}
public int compareTo(MyObject another) {
if (getDate() == null || another.getDate() == null) {return 0;}
return getDate().compareTo(another.getDate());
}
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(flags);
}
public static final Parcelable.Creator<MyObject> CREATOR = new Parcelable.Creator<MyObject>() {
public MyObject createFromParcel(Parcel in) {
return new MyObject(in);
}
public MyObject[] newArray(int size) {
return new MyObject[size];
}
};
private MyObject (Parcel in) {
flags = in.readInt();
}
}
는 확인 my_array.get (위치)는 parcelable 객체를 반환 있습니까? –
게시물 MyObject.java – pskink