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

Unable to complete task 2of2 in 'improving our code'. "Now add a String member variable, name it mTitle make it public."

This is what I type: public class PictureBook{ public String mTitle() {
} }

I am then returned with 1 error: expecting ...(something)

PictureBook.java
public class PictureBook{
  public String mTitle() {   
  }
}

2 Answers

Stone Preston
Stone Preston
42,016 Points

the task states: Now add a String member variable, name it mTitle make it public.

you added a method, not a variable. to declare a member variable, simply provide the type and the name for the variable (member variables conventionally start with m), followed by a semicolon. dont forget to make it public:

public class PictureBook{
  public String mTitle;
}

methods have a return type, a name, and a parameter list that goes in between parenthesis.

public String mTitle() {   
  }

the code above creates a method called mTitle that returns a string and takes no arguments. the task asked for a variable, not a method, which is why the above code is incorrect.

Thank you. I had the same problem and your answer was very helpful.

You guys are insanely fast. Thank you for the assist!

Stone Preston
Stone Preston
42,016 Points

no problem, glad I could help