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 trialIvan Bodnar
1,197 Pointscrystalball cannot be resolved to a type
I get the error message "crystalball cannot be resolved to a type"
Help?
public class MainActivity extends Activity {
private Crystalball mCrystalball = new CrystalBall();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Declare our view variables
final TextView answerLabel = (TextView) findViewById(R.id.textView1);
Button getAnswerButton = (Button) findViewById(R.id.button1);
getAnswerButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
String answer = mCrystalBall.getAnAnswer();
//Update the label with our dynamic answer
answerLabel.setText(answer);
6 Answers
Gergő Bogdán
6,664 PointsYou should write types in CamelCase, the problem is you wrote Crystalball (small b in ball) and the type is CrystalBall (Ball with capital b)
Ivan Bodnar
1,197 PointsI tested your solution but I get the same error...
Ben Jakuben
Treehouse TeacherIvan Bodnar, can you paste in your code from CrystalBall.java?
Ivan Bodnar
1,197 PointsSure:
package com.example.crystalball;
import java.util.Random;
public class crystalBall {
// Member variables (properties about the object)
// Methods (abilities: things the object can do)
public String getAnAnswer() {
String[] answers = {
"It is certain",
"It is decidedly so",
"All sings YES",
"The stars are not aligned",
"My reply is NO",
"It is doubtful",
"Better not tell you know",
"Concentrate and ask again",
"Unable to answer now",
};
// The button was clicked, so update the answer label with an answer
String answer = "";
//Random select one of three answers: yes, no or maybe
Random randomGenerator = new Random(); // Construct a new Random number generator
int randomNumber = randomGenerator.nextInt(answers.length);
/* Convert the random number to a text answer
* 0 = Yes
* 1 = No
* 2 = Maybe
*/
answer = answers[randomNumber];
return answer;
}
}
Ben Jakuben
Treehouse TeacherAh, check out your class name. It has a lowercase "c". You either need to change it to an uppercase "c" or use the lowercase version everywhere. Java convention is to use uppercase for class names, so I'd go that route. :)
Gergő Bogdán
6,664 PointsNow its clear what is the issue. In Java the name of the class has to be exactly the same as the name of the file which contains it. So in your case if the .java file the CrystalBall class is is implemented is named as <b>CrystalBall</b> then the name of the class inside the code file has to be the exactly the same, which in your case is not (crystalBall). Please try to write in the class declaration the exact name which you have as file name. That should resolve your issue.
Ivan Bodnar
1,197 PointsI guess I missed the beginning:
package com.example.crystalball;
import java.util.Random;
public class crystalBall { // Member variables (properties about the object)
// Methods (abilities: things the object can do)
public String getAnAnswer() {
String[] answers = {
Ivan Bodnar
1,197 PointsOkkkk!!! Now it's working! Thank you both guys.
Ps: sorry I kind of broke your Crystals ;)
Ben Jakuben
Treehouse TeacherGlad you got it! :)