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
james white
78,399 PointsAndroid WeatherApp Creating a model object POJO Challenge
Challenge Link: http://teamtreehouse.com/library/build-a-weather-app/working-with-json/creating-a-model-object
Challenge Task 1 of 3
More POJO practice! POJO stands for "Plain Old Java Object." Create a new public class called Movie.
Challenge Task 2 of 3
Now add two private member variables: a String called mTitle and an int called mYearReleased.
I easily passed the first two challenges with this code:
public class Movie{
private String mTitle;
private int mYearReleased;
}
Now I'm on to the third challenge:
Challenge Task 3 of 3
To complete our POJO, add getters and setters for each member variable. Ignore the 'm' prefix when naming your getters and setters. :)
Here's my code:
public class Movie{
private String mTitle;
private int mYearReleased;
public String getTitle() {
return mTitle;
}
public void setTitle(String title) {
title = mTitle;
}
public int getYearReleased() {
return mYearReleased;
}
public void setTitle(int yearReleased) {
yearReleased = mYearReleased;
}
}
The error it gives is:
Bummer!
The naming convention is 'setVariableName' (without the 'm' prefix).
I really don't think I am using the 'm' prefix in my getters and setters..
Am I?
I really don't know what it wants..
2 Answers
james white
78,399 PointsThanks Gergo!
Of course that's why it thought I was using the 'm' prefix naming convention,
because the values assignment was reversed..
The code (updated to pass):
public class Movie{
private String mTitle;
private int mYearReleased;
public String getTitle() {
return mTitle;
}
public void setTitle(String title) {
mTitle = title;
}
public int getYearReleased() {
return mYearReleased;
}
public void setYearReleased(int yearReleased) {
mYearReleased = yearReleased;
}
}
Gergő Bogdán
6,664 PointsHi,
Your naming of methods is correct. The m prefix for the class variables is used to easily distinguish them from other local variables which can appear in a method for example.
You have one error though, in the setter methods, you are updating the passed in value instead of updating the class variables:
public void setTitle(String title) {
title = mTitle;
}
You should reverse the value setting, because you want to store the value inside the class.
public void setTitle(String title) {
mTitle = title;
}
Also I noticed you have 2 methods defined with the same name: setTitle, you should have a set method for mYearReleased variable, called setYearReleased.
