インテント経由でカスタム データを送信するために、スニペットに基づいて独自の Parcelable クラスを作成しました。それを使用すると、Android (最小 API 10) で例外が発生します。以下のコードの何が問題なのですか? 最小限に切り詰めました。ここにあります:
public class MyParcelable implements Parcelable {
private float[] data = null;
public MyParcelable(float[] data) {
this.data = data;
}
public MyParcelable(Parcel in) {
/* After this line the exception is thrown */
in.readFloatArray(data);
}
public static final Creator<MyParcelable> CREATOR = new Creator<MyParcelable>() {
public MyParcelable createFromParcel(Parcel in) {
return new MyParcelable(in);
}
public MyParcelable[] newArray(int size) {
return new MyParcelable[size];
}
};
public int describeContents() {
return this.hashCode();
}
public void writeToParcel(Parcel out, int flags) {
out.writeFloatArray(data);
}
public float[] getData() {
return data;
}
}