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];
}
};
}
Bất cứ khi nào tôi sẽ truy xuất các byte trong mảng sau, nó sẽ trả về ngoại lệ là NullPointerException
. Ai có thể nói vấn đề là gì? Những gì tôi đang cố gắng làm là chuyển một byte hình ảnh đã tải xuống từ hoạt động này sang hoạt động khác.Chuyển ByteArray qua Parcel trả về NullPointerException
Ý anh là cái gì đó như: public void readFromParcel (Parcel in) { _byte = byte mới [length_of_byte]; in.readByteArray (_byte); } – Debopam
Viết ... 'dest.writeInt (_byte.length); dest.writeByteArray (_byte); 'và đọc ...' _byte = new byte [in.readInt()]; in.readByteArray (_byte); ' –
ok .. hãy để tôi kiểm tra .. – Debopam