Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Simple Android App (2014) Improving Our Code Creating a Class

String member variable

Challenge: "Now add a String member variable named mTitle. Make it public."

public String mTitle() { }

Could anyone tell me what I'm doing wrong?

7 Answers

Stone Preston
Stone Preston
42,016 Points

it looks like you created a method, not a variable. (methods have () { } after them while variables do not). you can declare a public member variable like so:

public class SomeClass {

    public dataType mVariableName;

}

you just need to declare the string variable named mTitle

public class PictureBook {

    public String mTitle;
}

thanks

Jimmy Ma
Jimmy Ma
5,796 Points

For the Updated 2017 course:

public class PictureBook { public String title;}

This took me a little while to figure out.

luke moloney
luke moloney
2,347 Points

Thx for the heads up Jimmy Ma!!

thanks too

thanks too

Thanks.

public class PictureBook { public String mTitle;}