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
Anthony Rubio
662 PointsparseColor
public int getColor(){
String Color = "";
//click to choose a random fact
Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(mColors.length);
Color = mColors[randomNumber];
int colorAsInt = Color.parseColor(color);
return colorAsInt;
}
}
Why is parseColor showing up red and color underlined red? am i supposed to import it or something?
3 Answers
Daniel Hartin
18,106 PointsHi Bjorn
If Anthony has followed the fun facts app course correctly the mColours String array will be declared in the onCreate() method of his ColorWheel class. I assume he only posted the getColour() method from his code.
if it wasn't declared correctly android studio should underline the mColours variable in red which he hasn't mentioned, the problem lies with the Colour.parseColor(colour) method call.
I think because he has named his String variable Color but used color(lowercase c) android studio can't find a correct string (as Color is a class) to pass to the parseColor() method call so is resulting in an error.
Daniel
Daniel Hartin
18,106 PointsYour String variable Color starts with a capital C, change this to a lowercase c and the code should work fine!
(Java naming convention dictates that variable names should start with a lowercase letter then have an uppercase letter on the first letter of any other words that have been joined to make a variable name i.e thisIsAGoodVariableName)
Hope this helps
Daniel
Bjorn Theart
711 PointsHi Anthony
Where do you get or declare the mColors variable? You are trying to access mColors.length but I don't see it declared anywhere in your code