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 trialVarad Ganjoo
679 PointsFor 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
Courses Plus Student 13,077 PointsI 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:
- Declare member variables (this includes the entire String[] mColorsArray)
- 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
- They can be made available to multiple methods inside a class or to other classes entirely.
- They can be easily organized and read for the future if need need be.
- 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.
Varad Ganjoo
679 PointsVarad Ganjoo
679 PointsThank you!
Eric De Wildt
Courses Plus Student 13,077 PointsEric De Wildt
Courses Plus Student 13,077 PointsDid this work for you? If so please vote my answer as the best answer.