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 trialAdam Morbacher
653 PointsshowFactButton.SetOnClickListener(listener);
Hello, im having a problem with a SetOnClickListener(listener); Whole code seems to be ok but the only part thats wrong is showFactButton.SetOnClickListener(listener); Even when i try to start my app it crashes because of this problem.
Here is the whole java code :
package eu.vybafkam.funfactssecondtry;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class FunFactss extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fun_factss);
//Declare our View Variables and assign the Views from the layout file
final TextView factlabel = (TextView) findViewById(R.id.factsTextView);
Button showFactButton = (Button) findViewById(R.id.showFactButton);
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
//The button was clicked so update the fact label with a new fact
String fact = "Ostriches can run faster then horses.";
factlabel.setText(fact);
}
};
showFactButton.SetOnClickListener(listener);
}
}
2 Answers
Steve Hunter
57,712 PointsYou want a small s at the start of the method name set
not Set
- it is showFactButton.setOnClickListener(listener)
Did that fix it?
Steve.
Adam Morbacher
653 PointsHello, thank you for an quick answer! YEA, it fixed my problem i will pay more attention on upper and lower case letters.
Steve Hunter
57,712 PointsGlad it worked! :-)