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

Android Build a Simple Android App (2014) Basic Android Programming Adding the onClick() Method

the showFactButton is highlighted red an wont let me run app need help, why is it red?

even when i copy an paste the code from the site its still red need help

it says cannot resolve symbol

3 Answers

Dhruv Gupta
Dhruv Gupta
4,320 Points

Two potential things,

You haven't initialized a button like this. private Button showFactButton;

Or you haven't found the id

showFactButton = (Button) findViewbyId(R.id.showfactbutton);

Apart from that my guess is as good as yours

thanks you helped me figure it out, i appreciate it

Angel Sosa
Angel Sosa
892 Points

Hello guys, Im having this issue(.setOnClickListener is showing in red):

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 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 v) {
        //The button was clicked, so update the fact label with new fact
        String fact = "Cristo es que salva!";
        factLabel.setText(fact);

    }
};
showFactButton.setOnClickListener(listener);

}