No generated R.java file in my project

Jonas picture Jonas · Nov 3, 2010 · Viewed 120.5k times · Source

I am doing the Notepad tutorial, exercise 2. I started by creating a new Android project and chose Create from source to import the downloaded source files for the excercise.

But now I get many errors in Eclipse, and the problem is that there is no generated R.java class. How can I solve this? The folder gen/ is empty.


I have errors on Notepadv2.java and in res/layout/note_edit.xml and both seems to be related to the fact that the generated R.java is missing.

Here is my import statements in Notepadv2.java:

import android.R;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter; 

They are created by the Eclipse command Ctrl+Shift+O.

Answer

Octavian A. Damiean picture Octavian A. Damiean · Nov 3, 2010

Go to Project and hit Clean. This should, among others, regenerate your R.java file.

Also get rid of any import android.R.* statements and then do the clean up I mentioned.

Apparently Jonas problem was related to incorrect target build settings. His target build was set to Android 2.1 (SDK v7) where his layout XML used Android 2.2 (SDK v8) elements (layout parameter match_parent), due to this there was no way for Eclipse to correctly generate the R.java file which caused all the problems.