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 trialBojana Skarich
3,260 PointsNot sure why my getter method isn't working. Please help!
Here is my code: public class GoKart { private String mColor = "red"; public String getmColor() { } return mColor; }
public class GoKart {
private String mColor = "red";
public String getmColor() {
} return mColor;
}
5 Answers
David McCarty
5,214 PointsIt's not working probably because your return statement is outside of the getmColor function. Move the return statement back inside of the curly braces and you should be good to go!
rtholen
Courses Plus Student 11,859 PointsPrefixing an "m" to variables is a convention or self-documenting policy many developers use to indicate the variable, like mColor, is a "member variable" of the class, as opposed to a local variable. It is not required but appears to be the convention followed at Treehouse.
Bojana Skarich
3,260 PointsDavid, Thank you for your tip. I moved the return mColor statement to the inside of the getmColor function, and now I am getting a different error: " Bummer! The method name should match more or less your field name. Expected getColor." I am not sure what I am doing wrong here. This is a frustrating exercise and I don't think the video explained this concept well.
Bojana Skarich
3,260 PointsI removed the "m" from my getmColor method, so that it is just getColor. I am still confused as to why we are using "m" at all. This is super confusing and I don't think the video did a good job explaining why we are using this in the first place.
David McCarty
5,214 PointsYeah it can be confusing at times. Just stick with it and don't be afraid to look some stuff up on Google or something similar if you need help with a specific area quickly.
Did you get past your problem?
Bojana Skarich
3,260 PointsYes I did get past this problem. Thanks for your help David!
David McCarty
5,214 PointsIf you want, since you got the problem sorted, you can choose my answer as best answer so people know the problem was solved! :)