user1452494
user1452494

Reputation: 1185

findViewByID(R.id.Button1) method not recognizing "id" in argument

For some reason, the "id" in the argument is underlined in red and is "not resolved and or not a field"

import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.os.Bundle;
import android.widget.Button;

public class Main extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button toggleButton = (Button)findViewById(R.id.toggleButton);
    toggleButton.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

            }
    });
}

}

Upvotes: 1

Views: 4954

Answers (4)

Jay
Jay

Reputation: 694

Just Click on Build Button (Green Hammer).

//Done

Upvotes: 0

SKT
SKT

Reputation: 1851

It is a problem faced in eclipse IDE. I had this problem

  • When there was an error in one of my xml files
  • When the package definition in my manifest file has changed
  • When my generated file is in another package.

Check if any of the above is your problem. May be it will help

Cleaning and building the project might also help you

Upvotes: 1

Sarim Sidd
Sarim Sidd

Reputation: 2176

Check your gen[Generated Java Files] folder in package explorer.

It may be empty, try

Project --> Clean

This will Generate files

Hope This Helps

Upvotes: 2

Swayam
Swayam

Reputation: 16354

It is one of the problems everyone faces with EclipseIDE. Clean your project and build it once again.

P.S. : Also make sure that the id of the Button in your mail.xml is android:id="@+id/toggleButton"

Upvotes: 1

Related Questions