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 trial

Android Android Lists and Adapters (2015) Using Parcelable Data Writing Parcelable Data

Zubeyr Aciksari
Zubeyr Aciksari
21,074 Points

Write the member variables to the dest Parcel in the writeToParcel() method. Use the appropriate write methods!

Hi, i am new to this, can someone please let me know where i am wrong and what i should do? Thanks!

VideoGame.java
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) {
        // Task 1 code here!   
      dest.wrtieString(mTitle);
      dest.writeDouble(mTitle);
      dest.writeLong(mHour);
    }
}

7 Answers

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);// Task 1 code here!   
}

} tel if yu a stil stuck

dest.writeString(mTitle); dest.writeInt(mYear);

Ben Junya
Ben Junya
12,365 Points

Ah Ha! Found it!

Check in the method - "writeToParcel" that nothing is misspelled. You misspelled "Write"

Instead of dest.wrtieString(mTitle);

change it to writeString(mTitle);

Misspelling is a common thing in coding, so make sure that you're double checking if everything is spelled correctly. It sounds silly and dumb, but it makes all the difference.

Good luck! happy coding!

Zubeyr Aciksari
Zubeyr Aciksari
21,074 Points

It still doesn't work, i don't know what to do.. Thanks for your help in advance!

Ben Junya
Ben Junya
12,365 Points

Hey dude,

Help me out a little bit here. What error messages are you getting?

Can you show me your stacktrace in the editor? Click "Preview," or the button that's next to the "Submit code" button in the challenge.

Ben Junya
Ben Junya
12,365 Points

I know you're really new, but it would probably be good for you to check out Android's documentation on Parcel objects.

If you don't know much of the language of that documentation, check out the Java basics course on Treehouse. The instructor is great!

Zubeyr Aciksari
Zubeyr Aciksari
21,074 Points

This is what i try: 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) {
    // Task 1 code here!   
     dest.writeString(mTitle);
     dest.writeDouble(mTitle);
     dest.writeLong(mHour);
}

}

Ben Junya
Ben Junya
12,365 Points

Couple of things:

1: What is the error being shown? Click Preview next to "Submit code" or tell me what the red bar at the top is saying. It's much more difficult for me to help you out if I don't know what errors you're getting.

2: Has the member class variable mHour been declared? Where is it coming from? Have you tried omitting that line in writeToParcel?

Zubeyr Aciksari
Zubeyr Aciksari
21,074 Points

And this is the preview: ./VideoGame.java:21: error: cannot find symbol dest.writeDouble(mTitle); ^ symbol: method writeDouble(String) location: variable dest of type Parcel ./VideoGame.java:22: error: cannot find symbol dest.writeLong(mHour); ^ symbol: variable mHour location: class VideoGame 2 errors

Ben Junya
Ben Junya
12,365 Points

Disclaimer: I've never done this particular course, but I know how to write Adapters from scratch in Android, and it looks like most of your errors are actually basic Java errors. I'll be happy to help out with that.

You have a type error:

mTitle is not a double, so dest.writeDouble(mTitle) is throwing your first error. Change that line to dest.writeString(mTitle);

The second error is because you never declared mHour. You can declare it at the top as a member class variable. Just make sure your types match. Since you're declaring it as a long, make sure you declare it as "public long mHour;"