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

Challenge task error - Simple Android app

//Challenge Task 2 of 2

//Now add a String member variable named mTitle. Make it public.

public class PictureBook{

public String mTitle(){
  String Title="lkjokj";

return Title ;
}
}

// Bummer! Make sure you are declaring a member variable in the class named 'mTitle'. Preview Get Help Recheck work

Any help please

4 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Hey Aboobaker, you had most of the correct code in your original post. What happens if you replace this code:

(){
  String Title="lkjokj";

return Title ;
}

with just a semicolon? Adding a member variable should only be one line of code. Parentheses and curly braces are for methods, not single variables. :)

It's work :)

thanks a lot coach Ben

what do you mean with just a semicolon?

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Ismael Soumahoro , the code I highlighted above isn't needed for this challenge. Declaring a member variable just needs three words and a semicolon. Check out the 2:50 mark of this video. The example in the video is for a TextView member variable, but in the challenge it just needs to be a String variable.

Hendy Budhigraha
Hendy Budhigraha
17,328 Points

Maybe you can try the following code:

public String mTitle;

Thanks for helping

I tried your answer, but it's not work.

code:

public class PictureBook{

  public String mTitle;
  {


  return mTitle;
  }
  }
Ayaz Parwaiz
PLUS
Ayaz Parwaiz
Courses Plus Student 2,284 Points

Dear Aboobaker,

Syntax for member variable is [DataType] [VariableName];

For Example I want to create a String member variable of name "MyName", then the code will be. String MyName="";

Thanks for helping

they ask me to make it "public" String, Task: (Now add a String member variable named mTitle. Make it public)

so I tried your answer, but it's not work :(

Ayaz Parwaiz
PLUS
Ayaz Parwaiz
Courses Plus Student 2,284 Points

Dear Aboobaker, You are doing wrong code. Correct code is


public String mTitle;