Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialHarley Urquhart
26,203 Pointsi think this is editor issue ...
ive referenced http://developer.android.com/reference/android/os/Parcelable.html and it doesnt work ??? any ideas
public class VideoGame implements Parcelable {
public String mTitle = "";
public int mYear = 0;
public VideoGame() {
// intentionally blank
}
// getters and setters omitted for brevity!
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(mTitle);
dest.writeInt(mYear);
}
public VideoGame(Parcel in) {
// Task 1 code here!
in.readString();
in.readInt();
}
public static final Creator<VideoGame> CREATOR = new Creator<VideoGame>() {
@Override
public VideoGame createFromParcel(Parcel source) {
// Task 2 code here!
return new VideoGame(source); // i dont get why this is not working???
}
@Override
public VideoGame[] newArray(int size) {
// Task 3 code here!
return new VideoGame[0];
}
};
}
3 Answers
william parrish
13,774 PointsTask 2 is correct, you are not doing anything wrong there.
Task 1 is not correct ( even though it allowed you to proceed, this is a big and they should / will likely fix it )
Task 1 being incorrect, causes the constructor in task 2 to fail.
To fix task 1:
You need to read the values from the parcel, and assign them to mTitle and mYear.
for example
mTitle = parcel.readString(); mYear = parcel.readInt();
when you do this correctly step two will pass, and you should be good to go.
Harley Urquhart
26,203 Pointsthanks will i submitted a bug but have a look over at this link http://developer.android.com/reference/android/os/Parcelable.html it is also quite misleading lol and i got the task done before i saw this post thanks man
william parrish
13,774 PointsTherein lies the rub,
On DAC the big difference that allows their example to work is addition of a separate constructor, that handles object creation from a parcel.
private MyParcelable(Parcel in) {
mData = in.readInt();
}
The absence of a parcel specific constructor in the above coding exercise, is the reason you have to set those fields yourself.
Anywho, glad you got sorted all the same.