Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Adam Morbacher
Adam Morbacher
653 Points


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 {

    protected void onCreate(Bundle savedInstanceState) {

            //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() {
            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.";


2 Answers

You want a small s at the start of the method name set not Set - it is showFactButton.setOnClickListener(listener)

Did that fix it?


Adam Morbacher
Adam Morbacher
653 Points

Hello, thank you for an quick answer! YEA, it fixed my problem i will pay more attention on upper and lower case letters.

Glad it worked! :-)