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
Derek Kneisel
2,487 PointsHaving trouble with a challenge
challenge question: Now add a String member variable named mTitle. Make it public.
Code I tried but doesn't work:
public class PictureBook {
public String mTitle (){ } }
4 Answers
Mark Josephsen
8,803 PointsMaybe something like: public String mTitle = new String();
Stone Preston
42,016 Pointsyou created a method, not a variable.
methods have (){ } after them, variables declarations just end in a semicolon.
all you need to do is declare the variable:
public class PictureBook {
public String mTitle;
}
it doesnt tell you to assign it anything which is why assumed it wants just the declaration.
Travis Carney
Front End Web Development Techdegree Graduate 17,797 PointsDoing this didn't work for me but doing what Mark Josephsen suggested did work. Maybe something is broke in the challenge and its looking for a variable instead?
Stone Preston
42,016 Pointsjust tried it again and it worked using
public class PictureBook {
public String mTitle;
}
Mark Josephsen
8,803 PointsThere's no return type. Is it void?
Mark Josephsen
8,803 PointsWait a second, that's a method, not a variable.
Derek Kneisel
2,487 PointsDerek Kneisel
2,487 PointsThat worked thanks