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 trialBrian McIver
1,156 PointsMember Variable "Improve Our Code Stage 5"
I'm just having a problem understating what I'm missing here. My code checks out in the preview, and when I look at my code from the lesson everything looks right, but when I "Check work" I get "Make sure you are declaring a member variable in the class named 'mTitle'."
public class PictureBook {
public String mTitle() {
String mTitle = "";
return mTitle;
}
}
2 Answers
Dan Johnson
40,533 PointsMember variables need to be declared outside of any methods, like this:
public class PictureBook
{
public String mTitle;
}
Variables declared in a method will be local to that method.
Brian McIver
1,156 PointsOkay so I was mostly messing it up with the ()? By adding the parentheses it then wants a value and a return?
Dan Johnson
40,533 PointsYou've declared a method called mTitle that returns a String and takes no arguments. The String you declared inside the method will be created each time the method is called, and then it's value will be returned (which in this case will be the empty string).