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
Darin Martin
350 PointsError:(15, 5) error: method does not override or implement a method from a supertype
It appears my code is matching up with the vid, but I have red squiggles under @Override I have searched for solutions to resolve this, but have not found an answer yet. Tried clean and rebuild, restarted studio.Thanks for your help in advance!
@Override
protected void onCreate(Bundle savedInstanceState, final ActionBar.Tab factLabel) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fun_facts99);
// Declare our view variables and assign them the Views from the layout file
final TextView factLable = (TextView) findViewById(R.id.factTextView);
Button showFactButton = (Button) findViewById(R.id.showFactButton);
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View view) {
// The button was clicked, so update the fact label with a new fact
String fact = "Ostriches can run faster than horses";
factLabel.setText(fact);
}
};
showFactButton.setOnClickListener(listener);
Corrected misspelling, but now get
@Override
protected void onCreate(Bundle savedInstanceState, final ActionBar.Tab factLabel) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fun_facts99);
// 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) {
// The button was clicked, so update the fact label with a new fact
String fact = "Ostriches can run faster than horses";
factLabel.setText(fact);
}
};
showFactButton.setOnClickListener(listener);
squiggle on factLabel right under the //declare our view.... and error Error:(22, 24) error: variable factLabel is already defined in method onCreate(Bundle,Tab)
1 Answer
Daniel Hartin
18,106 PointsHi Darin
@Override
protected void onCreate(Bundle savedInstanceState) { //You added a factlabel declaration in here by mistake
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fun_facts99);
// 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) {
// The button was clicked, so update the fact label with a new fact
String fact = "Ostriches can run faster than horses";
factLabel.setText(fact);
}
};
showFactButton.setOnClickListener(listener);
I think you added the factlabel declaration as a paramater for the method call by mistake. The code above has removed this.
Hope this helps
Daniel
Darin Martin
350 PointsDarin Martin
350 PointsThank you! That was exactly the problem. Wonder how I did that? heh... hmmm Thanks a ton! :)
Daniel Hartin
18,106 PointsDaniel Hartin
18,106 PointsNo problem, happy coding :)