Search code examples
androidfindviewbyid

findviewbyid not working


Eclipse is not recognizing R.id. I just started learning Android so please help me out here.

 import android.app.Activity;
 import android.os.Bundle;
 import android.widget.EditText;

 public class SecondappActivity extends Activity {

     EditText ed;
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {

         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
         ed=(EditText) findViewById(R.id.b1);
    }
}

it is saying id cannot be resolved or is not a field


Solution

  • Check your xml file and make sure it doesn't have any error. Looks like there is a problem with generating R file. It can be caused by errors in xml.