title: Eclipse error : button1 cannot be resolved or is not a field
body: <p>Here is my MainActivity.java code :</p>
  
  <pre><code>package com.dg.buttontest3;
  import android.os.Bundle;
  import android.app.Activity;
  import android.util.Log;
  import android.view.Menu;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  public class MainActivity extends Activity implements OnClickListener{
  Button button;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      button = (Button)findViewById(R.id.button1);
      button.setOnClickListener(this);
  }
  
  @Override
  public void onClick(View v) {
      // TODO Auto-generated method stub
      Log.d("dg","button was clicked");
  }
  }
  </code></pre>
  
  <p>And here is the activity_main.xml code : </p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  
  &lt;Button
      android:id="@+id/button1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_alignParentTop="true"
      android:layout_marginLeft="18dp"
      android:layout_marginTop="18dp"
      android:text="Button" /&gt;
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I am getting the following error while running this code on Eclipse ADT : button1 cannot be resolved or is not a field.
  I don't understand what is wrong with my code. Please help.</p>