Writing arrays of Parcelables to a Parcel in Android

I'm trying to write an array of objects that implement [Parcelable][1] into a [Parcel][2] using [writeParcelableArray][3]. The objects I'm trying to write are defined (as you'd expect) as: public class Arrival implements Parcelable { /* All the right stuff in here... this class compiles and acts fine. */ } And I'm trying to write them into a `Parcel' with: @Override public void writeToParcel(Parcel dest, int flags) { Arrival[] a; /* some stuff to populate "a" */ dest.writeParcelableArray(a, 0); } When Eclipse tries to compile this I get the error: > 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 > I completely don't understand this error message. `Parcelable` is an interface (not a class) so you can't extend it. Anyone have any ideas? **UPDATE:** I'm having basically the same problem when putting an `ArrayList` of `Parcelable`s into an `Intent`: Intent i = new Intent(); i.putParcelableArrayListExtra("locations", (ArrayList) locations); yields: > The method putParcelableArrayListExtra(String, ArrayList< ? extends Parcelable >) in the type Intent is not applicable for the arguments (String, ArrayList< Location >) This may be because `Location` was the class I was working on above (that wraps the `Arrival`s), but I don't think so. [1]: http://developer.android.com/reference/android/os/Parcelable.html [2]: http://developer.android.com/reference/android/os/Parcel.html [3]: http://developer.android.com/reference/android/os/Parcel.html#writeParcelableArray%28T%5B%5D,%20int%29

以上就是Writing arrays of Parcelables to a Parcel in Android 的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准