Field in R.id can not be resolved problem

  • Replies:0
JOFIN JOHNSON
  • Forum posts: 1

Jul 12, 2013, 9:24:15 PM via Website

Hi guys, im a beginner to android development. I was developing a SilentModeToggle app which requires a button to toggle the silent mode to loud and viceversa.
The problem is even after i write xml code for button, it does not make corresponding id in R.java class with "build automatically" is checked in project menu. It is not there in R file when check it in package explorer. And it shows an error when i use this button id that " Button_name can not be resolved or not a field"
My code for button is shown below

XML code----
<Button
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Toggle Silent Mode" />

Java button setting function---
private void setButtonClickListener() {
Button toggleButton = (Button) findViewById(R.id.toggleButton);
toggleButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
}
});

}

The bolded line shows error that "toggleButton can not be resolved or not in field"

please help

— modified on Jul 17, 2013, 2:55:48 PM

Reply