我正在尝试使用writeParcelableArray将一个实现Parcelable的对象数组写入Parcel。在Android中将包裹数组写入一个包裹
我想写的对象定义(如你所期望)为:
public class Arrival implements Parcelable {
/* All the right stuff in here... this class compiles and acts fine. */
}
我试图把它们写为'包裹”有:
@Override
public void writeToParcel(Parcel dest, int flags) {
Arrival[] a;
/* some stuff to populate "a" */
dest.writeParcelableArray(a, 0);
}
当Eclipse试图编译这个我得到的错误:
Bound mismatch: The generic method writeParcelableArray(T[], int) of type Parcel is not applicable for the arguments (Arrival[], int). The inferred type Arrival is not a valid substitute for the bounded parameter < T extends Parcelable >
我完全不明白此错误消息。 Parcelable
是一个接口(不是类),所以你不能扩展它。有人有主意吗?
UPDATE:
Intent i = new Intent();
i.putParcelableArrayListExtra("locations", (ArrayList<Location>) locations);
产量:我的推杆Parcelable
秒的ArrayList
时为Intent
具有基本相同的问题
The method putParcelableArrayListExtra(String, ArrayList< ? extends Parcelable >) in the type Intent is not applicable for the arguments (String, ArrayList< Location >)
这可能是因为Location
是我上面正在做的课程(包装Arrival
s),但我不这么认为。
正如我所说,使用接口声明你的数组。很高兴你能解决问题。 – harschware 2009-12-12 22:09:06