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

Manoj Abraham
Manoj Abraham
1,258 Points

What does the "...is not abstract..." error mean?

I get the following error when I try to run the app:

Error:(23, 68) error: <anonymous com.manojabraham.funfacts.FunFactsActivity$1> is not abstract and does not override abstract method onClick(View) in OnClickListener

Here is the code I entered/modified per the lesson:

package com.manojabraham.funfacts;

import android.app.Activity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;


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) {
                // 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);
    }

In the code window itself, the second View.OnClickListener is underlined in red. When I mouseover it, I see the following tool tip:

Class 'Anonymous class derived from OnClickListener' must either be declared abstract or implement abstract method 'onClick(View)' in 'onClickListener'.

Please help. I've gone over the code several times and can't seem to locate what I might have done wrong. Thank you in advance.

2 Answers

You've written:

 public void OnClick(View view)

Try with small "o".

public void onClick(View view)
Manoj Abraham
Manoj Abraham
1,258 Points

Thank you. How silly of me. I made the change and everything compiled just fine. Thanks again.