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 Blog Reader Android App Exploring the Master-Detail Template Blog Reader Project Overview

Ka Kai Chan
Ka Kai Chan
2,250 Points

Now add a new String variable named 'message' and set it equal to the second element in the array.

How is the code written? I have tried many times but not work.

4 Answers

You have to be a little bit more specific on your the problem you are having. if you have a variable of a type array the and they are asking for you to set the second element of that array with the variable message, it will look something along the lines of

String message = "hello there";
String[] myStringArray = {"im an array", message, "I am another element of the array" }

So what they are asking is to initialize a new variable and set that in the 2nd element or index 1 of the array.

Hope that helps!

Nick Edwards
PLUS
Nick Edwards
Courses Plus Student 15,766 Points

I think it's the other way around actually - they already have a String Array and are asking the user to create a new String variable and set it to the second element of that Array:

String[] myStringArray = {"one", "two", "three"};
String message = myStringArray[1];

Ka Kai Chan, don't forget that Arrays start counting from 0, not 1. So the first element of an array is 0, the second is 1, and so on.

Upvoting your answer, Nick, just looked at the challenge and it fits the context.

Ka Kai Chan
Ka Kai Chan
2,250 Points

Thanks all, I pass the code challenge for this stage. Thanks so much ! =]]]]