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 trialNeil Gittens
1,826 PointsCannot resolve symbol error in simple refactoring tutorial
After cutting and pasting code in a newly created class called FactBook i am receiving cannot resolve symbol errors throughout the program on various items.
example:
cannot resolve symbol "setText" cannot resolve symbol "showFactButton"
I have tried restarting Android studio.
Here is a screen shot
https://drive.google.com/file/d/0B9lIENS5Ktymd1dLT1lrQjAySUE/view?usp=sharing
----------------------code starts here--------------------------------------------------------
package com.example.Neil.funfacts;
import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.TextView;
import java.util.Random;
public class FunFactsActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fun_facts);
// Declare our View variables and assign them the views from the layout file
final TextView factLabel = (TextView) findViewById(R.id.factTextView);
Button showFactButton = (Button) findViewById(R.id.showFactButton);
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View view) {
}
// Update the label with our dynamic fact
factLabel.setText("");
}
};
showFactButton.setOnClickListener(listener);
}
}
---------------------------------------code ends here-----------------------------------------------------------
2 Answers
Ben Deitch
Treehouse TeacherIt looks like you've got an extra '}' in the onClick method. Also, the FactBook class should be in the same folder as FunFactsActivity.
public class FunFactsActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fun_facts);
// Declare our View variables and assign them the views from the layout file
final TextView factLabel = (TextView) findViewById(R.id.factTextView);
Button showFactButton = (Button) findViewById(R.id.showFactButton);
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View view) {
} // <-- Try deleting this <-----------------------------
// Update the label with our dynamic fact
factLabel.setText("");
}
};
showFactButton.setOnClickListener(listener);
}
}
Neil Gittens
1,826 PointsDude you are a life saver. I comb that code constantly and I don't believe I missed that. What can I say about fresh eyes and experience? I don't think I got to the part about moving the fun fact.
Thank you soooooo very much Ben
Neil Gittens
1,826 PointsI've tried cleaning cache, rebuilding etc. nothing worked. I'm almost at the point of deleting android studio.
Can anyone please help!! I've been trying solutions on my own. Searching the web constantly. I cannot move on from this point.
Neil
Ben Deitch
Treehouse TeacherBen Deitch
Treehouse TeacherCould you post the code?