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) Coding the Fun Facts Using an Array

maxmaltsev
maxmaltsev
3,419 Points

Extra Credit - Array Madness

Hi,

So i was trying to do an Extra Credit Task in Array Madness training at Android development section:

"Create a new project and add two TextViews to the screen. Create an array of numbers and see if you can display the numbers in order in the first TextView and then reversed in the second TextView."

What I'm I doing wrong? How make array numbers in order and reversed after?

   ```JAVA
   setContentView(R.layout.activity_array);

    TextView firstLabel = (TextView) findViewById(R.id.textView);//textview1
    TextView secondLabel = (TextView) findViewById(R.id.textView2);//textview2

    int myNumbers[] = {1,4,5,7,2,9,11,6,28,13}; // This is an array

    Arrays.sort(myNumbers); // Trying to sort it

    int firstTextView = myNumbers; // Wrong data type :(
    firstLabel.setText(firstTextView);

   ```
aakarshrestha
aakarshrestha
6,509 Points

You are missing index in the array you are using i.e. "firstLabel.setText(firstTextView[provide the index here]);"

   setContentView(R.layout.activity_array);

    TextView firstLabel = (TextView) findViewById(R.id.textView);//textview1
    TextView secondLabel = (TextView) findViewById(R.id.textView2);//textview2

    int myNumbers[] = {1,4,5,7,2,9,11,6,28,13}; // This is an array

    Arrays.sort(myNumbers); // Trying to sort it

    //Interating through the array list.
    for(int i =0; i < myNumber.length; i++){
             firstLabel.setText(myNumbers[i]); //you need to provide an index, which is "i" in this case, so the code knows from which position of the array it should start reading.
    }

Hope it clears your confusion.

Happy coding!