Error: R.java was modified manually! Reverting to generated version!

This error “R.java was modified manually! Reverting to generated version!” appears after compiling an Android application if there are inconsistency in the layout/main.xml file (or other one if you have more); you don’t have the same element you are trying to reach out in one of your Activity class.
For example:

1. This part is from the layout/main.xml :

< Button android:id=”@+id/searchBtn” android:layout_width=”117px”
android:layout_height=”wrap_content” android:text=”Search”
android:layout_x=”176px” android:layout_y=”31px”>
<  /Button>

2. This is from an activity class when you try add a mouse listener to the above “designed” button:
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class ShowElements extends Activity implements View.OnClickListener {

private Button searchbtn;
private EditText input;
private ConnectionUtilImpl connection = new ConnectionUtilImpl();

public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Capture button from layout

searchbtn = (Button)findViewById(R.id.searchBtn);

// ad listeners
searchbtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String searchedText = input.getText().toString();
input.setText(searchedText);
connection.connectToSocket();
...
}
});

}
// the rest
}

}

So, looking at the red code, you can hopefully understand what I mean by binding the element. If in the xml the name remains the default one(as is generated, for ex: android:id=”@+id/widget37″) then you are going to receive a nice error on compilation. You will see the error icon on the project as well, but because the syntax is correct you aren’t told that the issue is in the layout xml file.

Wait, the solution is not there yet. The last thing you should do is clean the project and build again, so that the file R.java is generated again. You can check that this time is correct by looking at the layout/main.xml file.
That’s it. Enjoy.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>