Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No generated R.java file in my project [duplicate]

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.

like image 729
Jonas Avatar asked Nov 03 '10 10:11

Jonas


2 Answers

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.

like image 70
Octavian A. Damiean Avatar answered Sep 24 '22 02:09

Octavian A. Damiean


After one whole day trying to find why R file was not generated, I found that after install Android SDK Tools r22 a new option in Tools was available: Android SDK Build Tools.

After installing it R file was generated again.

like image 43
Miguel Febres Avatar answered Sep 25 '22 02:09

Miguel Febres