Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find symbol class onClickListener

Tags:

java

android

I'm new to android development. Here's the problem i ran into. I'm using Android Studio. I looked up on many sites, they said to import the related class. Having done that, the problem remains. Any help is appreciated.


Can anyone please help me with this, i have been searching for a while now for the solution.

Here's the code:

package com.example.veeresh.myapplication;
//import statements
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button button1 = (Button)findViewById(R.id.button1);

        button1.setOnClickListener(
                //error: cannot find symbol class onClickListener
                new Button.onClickListener()
                {
                    public void onClick(View v)
                    {
                        TextView text1 = (TextView)findViewById(R.id.text1);
                        text1.setText("Veeresh Here");
                    }
                }
                );
    }
}

Error:

Error:(24, 27) error: cannot find symbol class onClickListener
Error:Execution failed for task ':app:compileDebugJava'.
Compilation failed; see the compiler error output for details.

like image 283
Veeresh Avatar asked Jul 21 '15 06:07

Veeresh


Video Answer


1 Answers

It should be new View.OnClickListener() instead of new Button.onClickListener()

OnClickListener with a capital O.

like image 127
sonic Avatar answered Oct 13 '22 07:10

sonic