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 trialkieran triggs
3,857 Pointswhat 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
Gunjeet Hattar
14,483 PointsHi 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
Gloria Dwomoh
13,116 PointsThe 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
2,389 Pointswhy should there not be a curly braces open and close after the line " public String mTitle; " ?
Gloria Dwomoh
13,116 Pointskieran 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
2,389 Pointsoh, okay, thanks, I was adding the curly braces and that was giving me an error.... Thanks for clearing it up
kieran triggs
3,857 Pointsok thanks for the help guys :D