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 Adding More Colors

For the part where I am supposed to write color.parseColor(color), the IDE is giving me an error. What should I do?

I cleaned it many times. Here is my code: package com.example.test2;

import java.util.Random;

public class ColorWheel { String [] mColors = {"#39add1","#3079ab", "#c25975","#e15258","#f9845b","#838cc7","#7d669e" ,"#53bbb4","#51b46d","#e0ab18","#637a91","#f092b0","#b7c0c7"};

    public int getColor() {

    String color = "";

    Random randomgenerator = new Random();
    int randomNumber = randomgenerator.nextInt(mColors.length);

    color = mColors[randomNumber];
    int colorAsInt = color.parseColor(color);

    return colorAsInt;
}

}

1 Answer

Eric De Wildt
PLUS
Eric De Wildt
Courses Plus Student 13,077 Points

I believe some of the problem lies in the fact that you are declaring your public variable in the wrong place. The proper code order is this:

  1. Declare member variables (this includes the entire String[] mColorsArray)
  2. Declare your methods

You have these steps intertwined by having the member variables inside the getColor method.

The reason we declare the variables as separate from the method is so that

  1. They can be made available to multiple methods inside a class or to other classes entirely.
  2. They can be easily organized and read for the future if need need be.
  3. They can be easily modified later incase such a need is required.

Try rewatching the video again and CAREFULLY compare your own code to Bens code. If by then you still have not gained the answers you seek then let me know and I will be happy to provide you with the proper code.

Thank you!

Eric De Wildt
Eric De Wildt
Courses Plus Student 13,077 Points

Did this work for you? If so please vote my answer as the best answer.