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 trialRazvan Sighinas
2,018 PointsIt doesn't recongnize ColorWhell class.Why?
It gives me this error:Error:(19, 13) error: cannot find symbol class ColorWheel
private ColorWheel mColorWheel = new ColorWheel();
and also
int color = mColorWheel.getColor();
At ColorWheel it says:Cannot resolve symbol 'ColorWheel' At getColor it says:Cannot resolve method 'getColor()'
4 Answers
Benoit Noyou
2,163 PointsDid you create the ColorWheel.java file and replace the various "fact" variables for "color"?
Razvan Sighinas
2,018 Pointsyes.
public class ColorWheel {
//Member variable(propertis about the object)
public String[] mColors = {
"#39add1",
"#3079ab",
"#c25975",
"#e15258",
"#f9845b",
"#838cc7",
"#7d669e",
"#53bbb4",
"#51b46d",
"#e0ab18",
"#637a91",
"#f092b0",
"#b7c0c7"
};
// Methods(abilities:things that object can do.)
public String getColor() {
String color = "";
// randomly select a fact
Random randomGenerator = new Random(); //Construct a new Random number generator
int randomNumber = randomGenerator.nextInt(mColors.length);
color = mColors[randomNumber];
int colorAsInt = Color.parseColor(color);
return colorAsInt;
}
}
Benoit Noyou
2,163 PointsYou must change the return type of the getColor() method to int, you should see a squiggly line under your return statement.
public String getColor(...
... return colorAsInt;
Razvan Sighinas
2,018 PointsI did it but getColor() and ColorWheel are still red.
erickrusznis
1,245 PointsI am having the same issue as this person, the private ColorWheel mColorWheel = new ColorWheel(); This throws an error "cannot resolve symbol 'ColorWheel' " Both ColorWheel's are red, as is the getColor method at the bottom. I did create the ColorWheel.java class, here is the FunFactsActivity.java public class FunFactsActivity extends AppCompatActivity { private FactBook mFactBook = new FactBook(); private ColorWheel mColorWheel = new ColorWheel(); // declare our view variables. private TextView mFactTextView; private Button mShowFactButton; private RelativeLayout mRelativeLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fun_facts);
// Assign the Views from the layout file to the corrssponding variables.
mFactTextView = (TextView) findViewById(R.id.factTextView);
mShowFactButton = (Button) findViewById(R.id.showFactbutton);
mRelativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout);
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
String fact = mFactBook.getFact();
int color = mColorWheel.getColor();
// Update the screen with our dynamic fact
mFactTextView.setText(fact);
mRelativeLayout.setBackgroundColor(color);
}
};
mShowFactButton.setOnClickListener(listener);
}
}
Here is the ColorWheel.java class: public class ColorWheel { // fields (member variables) - properties about the object private String[] mColors = { "#39add1", // light blue "#3079ab", // dark blue "#c25975", // mauve "#e15258", // red "#f9845b", // orange "#838cc7", // lavender "#7d669e", // purple "#53bbb4", // aqua "#51b46d", // green "#e0ab18", // mustard "#637a91", // dark gray "#f092b0", // pink "#b7c0c7" // light gray };
// Methods - actions object can take
public int getColor(){
String color;
// Randomly select a fact.
Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(mColors.length);
color = mColors[randomNumber];
int colorAsInt = Color.parseColor(color);
return colorAsInt;
}
}