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
zacharygassem
3,697 PointsCan't figure out how to solve the errors in my code(Android Fun Facts project)...Please help!
Here is my code in my ColorWheel.java class:
package com.example.zacharygassem.funfacts;
import android.graphics.Color;
import android.widget.RelativeLayout;
import java.util.Random;
/**
* Created by Zachary Gassem on 21/08/2014.
*/
public class ColorWheel {
{
//Member variables - properties about the object
public String[] mColors = {
"#39add1",
"#3079ab",
"#c25975",
"#e15258",
"#f9845b",
"#838cc7",
"#7d669e",
"#53bbb4",
"#51b46d",
"#e0ab18",
"#637a91",
"#f092b0",
"#b7c0c7"
};
//Method - Abilities (things the object can do)
public int 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;
}
}
My code in all the other files has no errors but this has please help
5 Answers
Justin Horner
Treehouse Guest TeacherHello Zachary,
In your code, I see you have two opening brackets like this
public class ColorWheel {
{
...
}
Try removing the one of the opening brackets.
I hope this helps.
zacharygassem
3,697 PointsI'm not sure why only a bit of the code is shown properly by the way
Justin Horner
Treehouse Guest TeacherHello Zachary,
Just want to let you know I took care of this for you. Check here to learn how to post your code on the forums in a way that will provide syntax highlighting and proper formatting.
I hope this helps!
zacharygassem
3,697 PointsThe errors are: Modifier public not allowed here (the public array), red squiggly line after semi - colon after curly braces surrounding array and Cannot resolve mColors.
ilias Georgakopoulos
22,866 PointsCheck my code if you want to compare it with yours.
public class ColorWheel {
public 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
};
// Method (abilities: things the object can do)
public int 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;
}
}
zacharygassem
3,697 PointsThanks I added an extra opening curly brace but I deleted it so everything is good now!