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

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;}