Question

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

Was it helpful?

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.

OTHER TIPS

Check for any errors in your xml files or your res folder. Clean and rebuild project. It will work

What does your main.xml file look like? There is nothing wrong with your java code. Assuming all your imports are working. Chances are bn1 is either not in that layout. Or you are not adding the '+' in you android:id field to make sure this goes into the R.java file.

Put

import YourWholePackage.R;

in import segment.

I have the same issue :/ I am just getting into android development and already stuck. This is my code:

class MainActivity : AppCompatActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
     super.onCreate(savedInstanceState)
     setContentView(R.layout.activity_main)
     EditText nameEditText = (EditText) findViewById(R.id.nameEditText)
  }
}

Nothing fancy, just one edittext field and one button, no errors in activity_main.xml. But when I am typing findViewById - its not even available in autosuggestion list. Thanks

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top