import android.os.Parcel;
import android.os.Parcelable;
public class MClass implements Parcelable {
private byte[] _byte;
public MClass() {
}
public MClass(Parcel in) {
readFromParcel(in);
}
public byte[] get_byte() {
return _byte;
}
public void set_byte(byte[] _byte) {
this._byte = _byte;
}
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeByteArray(_byte);
}
public void readFromParcel(Parcel in) {
in.readByteArray(_byte); //LOE - Line Of Exception
}
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public MClass createFromParcel(Parcel in) {
return new MClass(in);
}
public MClass[] newArray(int size) {
return new MClass[size];
}
};
}
每當我要檢索我的下列數組中的字節時,它將返回NullPointerException
的異常。任何人都可以說出什麼問題?我試圖做的是將一個下載的圖像字節從一個活動轉移到另一個活動。通過Parcel傳輸ByteArray返回NullPointerException
你的意思是這樣的:(在包裹) 公共無效readFromParcel { _byte =新的字節[length_of_byte]; in.readByteArray(_byte); } – Debopam 2012-07-29 13:21:28
在write ...'dest.writeInt(_byte.length); dest.writeByteArray(_byte);'和read ...'_byte = new byte [in.readInt()]; in.readByteArray(_byte);' – 2012-07-29 13:25:00
確定..讓我查一下.. – Debopam 2012-07-29 13:26:56