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 trialGanta Hemanth
6,460 Pointsproblem with createfromparcel()
THis is the question
Now it's time to work on the CREATOR variable. The first thing we need to do is return a new VideoGame in the createFromParcel() method. Make sure you use the source parameter!
It is showing me an error asking me to use the parcel variable source to create a new video game which i am doing already.. So i don't know why is it showing me an error..
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);
}
@Override
public VideoGame[] newArray(int size) {
// Task 3 code here!
return new VideoGame[0];
}
};
}
1 Answer
Patrick Corrigan
5,739 PointsThe problem is actually with your answer from part 1 (For some reason it lets you pass without a complete answer).
You need to make sure the values that you are pulling out of the Parcel are being assigned to the member variables. Like this:
public VideoGame(Parcel in) {
// Task 1 code here!
mTitle = in.readString();
mYear = in.readInt();
}
Ganta Hemanth
6,460 PointsGanta Hemanth
6,460 PointsTHanks for the reply.. Can you help me with this question??
I really don't understand how recycle view works. I am comfortable with using the view holder in the list view but i just don't get what is going on with the recycle view.
So how does recycle view work?? What makes it better than the list view with view holder?