"Id Cannot Be Resolved or Is Not a Field" Error

id cannot be resolved or is not a field error?

Do not modify the R class. The error means there's something syntactically wrong with your XML layouts and R cannot be auto-generated. Try looking there and post the xml code you're not sure about, if any.

Edit : also: remove "import android.R" from imports at top of file (if there)

button_id Cannot be resolved or is not a field

As i mentioned in my comments earlier, There is no button with id button_id..
instead you have android:id="@+id/button1" in your xml file..

so, please change

final Button button = (Button) findViewById(R.id.button_id); 

to

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

in MainActivity.java

OR

change

android:id="@+id/button1"

to

android:id="@+id/button_id"

in your activity_main.xml

Cannot be resolved or is not a field error android

I think that maybe is a problem of the imports. Try to check the imports of your class. Sometimes Eclipse imports the R class from the android package and stops using yours.
Remove imports like import android.R

Android/Eclipse Question - id cannot be resolved or is not a field error

I managed to fix the problem by simply restarting my computer. I guess in order for all the development tools to work properly a computer restart is necessary? I can't believe I didn't think about doing this before though. Thanks for those who tried to help.



Related Topics



Leave a reply



Submit