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

what is wrong with the following code?

what is wrong with the following code?

public class PictureBook{
  public String[] mTitle = {
"String", "String2"
};

}

it gives me an error saying make sure that mTitle is a string

3 Answers

Hi Kieran,

I just had a look at the code challenge . It is not asking you to create an array. It's asking you to creating a simple String variable.

Should have been simply public String mTitle;

And also it need not be initialized.

Hope this helps

The question asks you to do this... "Now add a String member variable named mTitle. Make it public." It doesn't ask you to make an array.

public class PictureBook{

  public String mTitle;

}
Shantanu Jain
Shantanu Jain
2,389 Points

why should there not be a curly braces open and close after the line " public String mTitle; " ?

kieran was creating an array of strings, hence added the brace after, but the questions doesn't ask for that. It just says we should make a public string member variable, that's why you don't need to add that and neither the bracket.

Shantanu Jain
Shantanu Jain
2,389 Points

oh, okay, thanks, I was adding the curly braces and that was giving me an error.... Thanks for clearing it up

ok thanks for the help guys :D