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 Improving Our Code Creating a New Class

Now add a String field (member variable) named mTitle. Make it public.

how do i complete the task above...i have tried to code like public class PictureBook{ public String mTitle(){ } } ...But it brings an error

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

3 Answers

When you're declaring a variable you don't use parenthesis and curly brackets those are for methods. You were close:

public class PictureBook{
  public String mTitle; //This is a variable you close it with a semi-colon

}
anil rahman
anil rahman
7,786 Points

What you have coded is a method not a variable:

public class PictureBook{
  public String mTitle(){ //method
  }
}

He states member variable named mTitle and make it public like this:

public class PictureBook {
    public String mTitle; //member variable
}
Dekel Zoaretz
Dekel Zoaretz
14,864 Points

Every statement that ends with parentheses is a method. that code that you have written is a method that returns a string and I don't think that what you want. The way to do it right is like Derek Markman wrote. In order to distinguish local variables and global variables it is a good practice to prefix the local variable with the char 'm'.